初学springmvc时遇到的一个问题
程序员文章站
2022-03-30 19:52:45
...
web.xml
Controller
报错信息
解决办法过滤所有请求<url-pattern>/</url-pattern>
Controller改为如下
在WEB/INF下建立views/hr/welcome.jsp
一开始welcome.jsp在views下面,就出错,不知道何故,记录下来
<?xml version="1.0" encoding="UTF-8"?> <!-- Copyright : adobocode.com , 2010 --> <web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"> <display-name>SampleSpringMVC</display-name> <!-- 载入Spring配置文件 --> <context-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/applicationContext.xml</param-value> </context-param> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <servlet> <servlet-name>SampleSpringMVC</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>SampleSpringMVC</servlet-name> <url-pattern>*.do</url-pattern> </servlet-mapping> <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> </filter> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> </web-app>
Controller
package com.boda.controller; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import com.boda.model.Department; import com.boda.service.DepartmentService; @Controller public class DepartmentController { @Autowired private DepartmentService departmentService; @RequestMapping(value = "department.do") public String create() throws Exception{ return "welcome"; } }
报错信息
javax.servlet.ServletException: Could not resolve view with name 'welcome' in servlet with name 'SampleSpringMVC' org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1029) org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:817) org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:719) org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:644) org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:560) javax.servlet.http.HttpServlet.service(HttpServlet.java:637) javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
解决办法过滤所有请求<url-pattern>/</url-pattern>
Controller改为如下
package com.boda.controller; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import com.boda.model.Department; import com.boda.service.DepartmentService; @Controller @RequestMapping(value = "hr/department/") public class DepartmentController { @Autowired private DepartmentService departmentService; @RequestMapping(value = "add") public String create() throws Exception{ return "hr/welcome"; } }
在WEB/INF下建立views/hr/welcome.jsp
一开始welcome.jsp在views下面,就出错,不知道何故,记录下来
推荐阅读
-
详解升级Android Studio3.0时遇到的几个问题
-
php MsSql server时遇到的中文编码问题
-
详解canvas绘图时遇到的跨域问题
-
Hibernate通过SQL查询常量时只返回第一个字符问题的解决方法
-
浅谈Android获取ImageView上的图片,和一个有可能遇到的问题
-
解决python给列表里添加字典时被最后一个覆盖的问题
-
.Net Core 发布到 Linux 上时遇到的问题记录
-
关于工作中.net转java遇到的一个远程调用传递重复参的问题。
-
Mysql数据库从5.6.28版本升到8.0.11版本部署项目时遇到的问题及解决方法
-
记录一下使用sea.js时遇到的几个小问题