为什么我的add.jsp会报404
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | package com.imooc.handler; import com.imooc.entity.Goods; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.servlet.ModelAndView; import java.util.Map; @Controller public class AonotationHandler { /** * 业务方法:model and view 完成数据的传递,视图解析 */ @RequestMapping ( "/modelAndViewTest" ) public ModelAndView modelAndViewTest(){ //创建modelandview对象 ModelAndView modelAndView = new ModelAndView(); //填充modelview对象 modelAndView.addObject( "name" , "tom" ); //设置逻辑视图 modelAndView.setViewName( "show" ); return modelAndView; } /** * 业务方法:Model传值,String进行试图解析 */ @RequestMapping ( "/ModelTest" ) public String ModeleTest(Model model){ //填充数据模型 model.addAttribute( "name" , "lucy" ); //设置逻辑视图 return "show" ; } /** * 业务方法 使用Map传值 String进行视图解析 */ @RequestMapping ( "/MapTest" ) public String MapTest(Map<String,String> map){ //填充数据模型 map.put( "name" , "ck" ); //设计逻辑视图 return "show" ; } /** * 添加商品展示 */ @RequestMapping ( "/addGoods" ) public ModelAndView addGoods(Goods goods){ System.out.println(goods.getName()); System.out.println(goods.getPrice()); ModelAndView modelAndView = new ModelAndView(); modelAndView.setViewName( "show" ); return modelAndView; } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | <? xml version = "1.0" encoding = "UTF-8" ?> < beans xmlns = "http://www.springframework.org/schema/beans" xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance" xmlns:context = "http://www.springframework.org/schema/context" xsi:schemaLocation = "http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd" > <!-- 将AonotationHandler自动扫描到IOC容器中--> < context:component-scan base-package = "com.imooc.handler" ></ context:component-scan > <!-- 视图解析器--> < bean class = "org.springframework.web.servlet.view.InternalResourceViewResolver" > <!-- 配置前缀--> < property name = "prefix" value = "/" ></ property > <!-- 配置后缀--> < property name = "suffix" value = ".jsp" ></ property > </ bean > </ beans > |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd" > < web-app > < display-name >Archetype Created Web Application</ display-name > <!-- 处理中文乱码--> < filter > < filter-name >encodingFilter</ filter-name > < filter-class >org.springframework.web.filter.CharacterEncodingFilter</ filter-class > < init-param > < param-name >encoding</ param-name > < param-value >UTF-8</ param-value > </ init-param > < init-param > < param-name >forceEncoding</ param-name > < param-value >true</ param-value > </ init-param > </ filter > < filter-mapping > < filter-name >encodingFilter</ filter-name > < url-pattern >/*</ url-pattern > </ filter-mapping > <!--设置访问静态资源 --> < servlet-mapping > < servlet-name >default</ servlet-name > < url-pattern >*.css</ url-pattern > </ servlet-mapping > < servlet > < servlet-name >SpringMVC</ servlet-name > < servlet-class >org.springframework.web.servlet.DispatcherServlet</ servlet-class > <!--配置SpringMVC.xml的路径--> < init-param > < param-name >contextConfigLocation</ param-name > < param-value >classpath:springmvc.xml</ param-value > </ init-param > </ servlet > < servlet-mapping > < servlet-name >SpringMVC</ servlet-name > < url-pattern >/</ url-pattern > </ servlet-mapping > </ web-app > |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | <%@ page contentType="text/html;charset=UTF-8" language="java" %> < html > < head > < title >add</ title > < link href = "css/bootstrap.min.css" rel = "stylesheet" > < style type = "text/css" > body{ overflow-x:hidden; } </ style > </ head > < body > < form class = "form-horizontal" role = "form" action = "addGoods" method = "post" > < div class = "form-group" > < label class = "col-sm-1 control-label" >名称</ label > < div class = "col-sm-3" > < input type = "text" class = "form-control" name = "name" placeholder = "请输入商品名称" > </ div > </ div > < div class = "form-group" > < label class = "col-sm-1 control-label" >价格</ label > < div class = "col-sm-3" > < input type = "text" class = "form-control" name = "price" placeholder = "请输入商品价格" > </ div > </ div > < div class = "form-group" > < div class = "col-sm-offset-1 col-sm-3" > < button type = "submit" class = "btn btn-default" >提交</ button > </ div > </ div > </ form > </ body > </ html > |
0
收起
正在回答 回答被采纳积分+1
1回答
chrismorgen
2019-04-04 15:55:11
你好同学,在WEB-INF目录下是无法直接访问add.jsp页面的,因为WEB-INF属于安全目录,无法通过url访问资源文件,所以你直接在url中访问才会出现404的错误,同学放在WEB-INF目录外就可以访问add.jsp页面了,祝学习愉快~
SSM主流框架入门与综合项目实战2018版
- 参与学习 人
- 提交作业 205 份
- 解答问题 4317 个
Java中非常实用的SSM整合开发内容,从Spring开始,到MyBaits的进阶内容,再到SpringMVC的应用,最后是SSM整合开发案例,逐步深入,助你成长为一名Java工程师!
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧