为什么我的不能咋控制台输出哎
package com.imooc.web.action;
import java.io.IOException;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.imooc.domain.Category;
import com.imooc.service.CategoryService;
import com.imooc.service.impl.CategoryServiceImpl;
/**
* Servlet implementation class CategoryServlet
*/
@WebServlet("/CategoryServlet")
public class CategoryServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//请求路径:localhost:8080/shop/CategoryServlet?method=findAll
String methodName=request.getParameter("method");
if("findAll".equals(methodName)) {
//查询所有分类
findAll(request,response);
//跳转到添加页面
}else if("saveUI".equals(methodName)) {
saveUI(request,response);
//保存分类的方法
}else if("save".equals(methodName)) {
save(request,response);
}
}
//后台分类管理,保存分类的方法
private void save(HttpServletRequest request, HttpServletResponse response) throws IOException {
//1.接受数据
String cname=request.getParameter("cname");
String cdesc=request.getParameter("cdesc");
System.out.println("接收的数据为:"+cname+" "+cdesc);
//2.封装数据
Category category=new Category();
category.setCname(cname);
category.setCdesc(cdesc);
//3.调用业务层处理数据
CategoryService categoryService=new CategoryServiceImpl();
categoryService.save(category);
//4.页面跳转
response.sendRedirect(request.getContentType()+"/CategoryServlet?method=findAll");
}
//后台分类管理跳转到添加页面
private void saveUI(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
request.getRequestDispatcher("/admin/category_add.jsp").forward(request, response);
}
//后台分类管理查询所有分类的方法
private void findAll(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//接受参数
//封装数据
//调用业务成处理数据
System.out.println("CategoryServlet的findALL方法执行了");
CategoryService categoryService=new CategoryServiceImpl();
List<Category> list=categoryService.findAll();
for(Category category:list){
System.out.println(category);
}
//页面跳转
request.setAttribute("list", list);
//请求转发
request.getRequestDispatcher("/admin/category_list.jsp").forward(request,response);
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
doGet(request, response);
}
}
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<!-- Mirrored from admindesigns.com/demos/absolute/1.1/admin_forms-validation.html by HTTrack Website Copier/3.x [XR&CO'2014], Thu, 06 Aug 2015 02:56:15 GMT -->
<head>
<!-- Meta, title, CSS, favicons, etc. -->
<meta charset="utf-8">
<title>油画商城--添加分类</title>
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath }/assets/skin/default_skin/css/theme.css">
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath }/assets/admin-tools/admin-forms/css/admin-forms.css">
<link rel="shortcut icon" href="${pageContext.request.contextPath }/assets/img/favicon.ico">
</head>
<body class="admin-validation-page" data-spy="scroll" data-target="#nav-spy" data-offset="200">
<div id="main">
<%@ include file="header.jsp" %>
<%@ include file="left.jsp" %>
<section id="content_wrapper">
<section id="content" class="table-layout animated fadeIn">
<div class="tray tray-center">
<div class="content-header">
<h2> 添加分类 </h2>
<p class="lead"></p>
</div>
<div class="admin-form theme-primary mw1000 center-block" style="padding-bottom: 175px;">
<div class="panel heading-border">
<form id="admin-form" name="addForm" action="${pageContext.request.contextPath }/CategoryServlet" method="post">
<input type="hidden" name="method" value="save">
<div class="panel-body bg-light">
<div class="section-divider mt20 mb40">
<span> 基本信息 </span>
</div>
<div class="section row">
<div class="section row">
<div class="col-md-2"></div>
<div class="col-md-1">
<label for="sn" class="field prepend-icon">
<label for="sn" class="field-icon">
名称
</label>
</label>
</div>
<div class="col-md-6">
<label for="sn" class="field">
<input id="sn" name="cname" class="gui-input" placeholder="名称" type="text" value="imooc"/>
</label>
</div>
</div>
<div class="section row">
<div class="col-md-2"></div>
<div class="col-md-1">
<label for="sn" class="field prepend-icon">
<label for="sn" class="field-icon">
描述
</label>
</label>
</div>
<div class="col-md-6">
<label for="address" class="field">
<input id="address" name="cdesc" class="gui-input" placeholder="描述" type="text" value=""/>
</label>
</div>
</div>
<div class="panel-footer text-center">
<button type="submit" class="button"> 保存 </button>
<button type="button" class="button" onclick="javascript:window.history.go(-1);"> 返回 </button>
</div>
</div>
</form>
</div>
</div>
</div>
</section>
</section>
</div>
<style>
/* demo page styles */
body { min-height: 2300px; }
.content-header b,
.admin-form .panel.heading-border:before,
.admin-form .panel .heading-border:before {
transition: all 0.7s ease;
}
/* responsive demo styles */
@media (max-width: 800px) {
.admin-form .panel-body { padding: 18px 12px; }
}
</style>
<style>
.ui-datepicker select.ui-datepicker-month,
.ui-datepicker select.ui-datepicker-year {
width: 48%;
margin-top: 0;
margin-bottom: 0;
line-height: 25px;
text-indent: 3px;
color: #888;
border-color: #DDD;
background-color: #FDFDFD;
-webkit-appearance: none; /*Optionally disable dropdown arrow*/
}
</style>
<script src="vendor/jquery/jquery-1.11.1.min.js"></script>
<script src="vendor/jquery/jquery_ui/jquery-ui.min.js"></script>
<script src="assets/admin-tools/admin-forms/js/jquery.validate.min.js"></script>
<script src="assets/admin-tools/admin-forms/js/additional-methods.min.js"></script>
<script src="assets/admin-tools/admin-forms/js/jquery-ui-datepicker.min.js"></script>
<script src="assets/js/utility/utility.js"></script>
<script src="assets/js/demo/demo.js"></script>
<script src="assets/js/main.js"></script>
<script type="text/javascript" src="js/pages.js"></script>
<script type="text/javascript" src="js/items.js"></script>
</body>
</html>
正在回答 回答被采纳积分+1
- 参与学习 人
- 提交作业 357 份
- 解答问题 8016 个
本阶段将带你学习MySQL数据库,JDBC接口,MyBatis框架等,带你掌握的数据的存放和管理。
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星