我是Spring和web MVC模块的新手.基本上,我有以下几点:
web.xml中
<servlet>
<servlet-name>abc-dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>abc-dispatcher</servlet-name>
<url-pattern>/user/*</url-pattern>
</servlet-mapping>
Run Code Online (Sandbox Code Playgroud)
ABC-调度-servlet.xml中
<?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-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<context:component-scan base-package="myPkg" />
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
<property name="prefix" value="/WEB-INF/pages/"></property>
<property name="suffix" value=".jsp"></property>
</bean>
Run Code Online (Sandbox Code Playgroud)
我有一个控制器,相关的部分是:
@Controller
public class ABCController {
@RequestMapping("/user/welcome")
public String printWelcome(ModelMap model) {
//code
}
Run Code Online (Sandbox Code Playgroud)
现在每当我尝试访问 http://localhost:8080/myapp/user/welcome
它给了我404.
日志说"映射url'/ user/welcome'到处理程序'ABCController'但是它无法在DispatcherServlet中映射名为'abc-dispatcher'的URI [/ MYAPP/user/welcome].
完全糊涂了.我已经检查了两次指定映射的所有线程,但这不是这里的情况.我肯定错过了什么!
谢谢您的帮助!
JB *_*zet 14
网址应该是http://localhost:8080/myapp/user/user/welcome.实际上,除非处理程序的alwaysUseFullPath属性设置为true,否则servlet-mapping将添加到请求映射URL以形成完整路径.
alwaysUseFullPath
如果为true,则Spring使用当前Servlet上下文中的完整路径来查找适当的处理程序.如果为false(缺省值),则使用当前Servlet映射中的路径.例如,如果使用/ testing/*映射Servlet并且将alwaysUseFullPath属性设置为true,则使用/testing/viewPage.html,而如果该属性设置为false,则使用/viewPage.html.
它已被添加context:component-scan到示例上下文文件片段中,但没有任何<annotation-driven/>元素表示spring框架要查找带注释的控制器@Controller
| 归档时间: |
|
| 查看次数: |
28182 次 |
| 最近记录: |