在添加页面点击添加后404(问题补充)
// product_add.jsp代码如下
<%@ 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="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="sn" class="field">
<input id="sn" name="sn" class="gui-input" placeholder="1000" type="text" value="1000"/>
</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="sn" class="field select">
<select id="departmentSn" name="departmentSn" class="gui-input" placeholder="分类..."><option value="10001" selected="selected">分类一</option><option value="10002">财务部</option><option value="10003">事业部</option></select>
<i class="arrow double"></i>
</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="name" class="field">
<input id="name" name="name" class="gui-input" placeholder="价格" type="file" value="上传图片"/>
</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>
// CategoryServlet代码如下:
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;
@WebServlet("/CategoryServlet")
public class CategoryServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// 请求路径
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);
}
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doGet(request, response);
}
/**
* 后台分类管理用于保存新分类的方法
* @param request
* @param response
*/
private void save(HttpServletRequest request, HttpServletResponse response) {
// 1、接收数据
String cname = request.getParameter("cname");
String cdesc = request.getParameter("cdesc");
System.out.println("接收的数据是:" + cname + " " + cdesc);
// 2、封装数据
// 3、调用业务层处理数据
// 4、页面跳转
}
/**
* 跳转到添加分类页面的方法
* @param request
* @param response
* @throws IOException
* @throws ServletException
*/
private void saveUI(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
request.getRequestDispatcher("/admin/category_add.jsp").forward(request, response);
}
/**
* 后台分类管理:查询所有分类的方法
* @param request
* @param response
* @throws IOException
* @throws ServletException
*/
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);
}
}
正在回答
同学你好,出现department/add路可能是同学jsp代码中有写这个路径。
同学可以在浏览器中检查看一下form表单要跳转的路径是否正确,如果不正确,同学应该根据项目中的Servlet路径进行修改。如下:
修改后再重启Tomcat,刷新一下浏览器或者换个浏览器访问试试。
如果我的回答解决了你的疑惑,请采纳!祝学习愉快!
- 参与学习 人
- 提交作业 357 份
- 解答问题 8016 个
本阶段将带你学习MySQL数据库,JDBC接口,MyBatis框架等,带你掌握的数据的存放和管理。
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星