我有 servlet xml 文件 personDetails-servlet.xml
<bean>
<mvc:annotation-driven />
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/jsp/yyy/config/" />
<property name="suffix" value=".jsp" />
</bean>
<context:component-scan base-package="com.ddd.config.controller" />
</beans>
和Web.xml条目
<servlet>
<servlet-name>personDetails</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>personDetails</servlet-name>
<url-pattern>/personDetails/*</url-pattern>
</servlet-mapping>
下面是 PersonDetailsController
package com.ddd.config.controller;
@Controller
public class PersonDetailsController {
@RequestMapping(value="/personDetails/personAddressDetails.html", method=RequestMethod.GET)
public String abc(ModelMap model) throws Exception{
}
}
我正在尝试输入 http://localhost:8080/myapp/personDetails/ConfgurationDetails.html 它不工作 当我尝试使用下面的一个时,它正在工作 http://localhost:8080/myapp/personDetails/personDetails/ConfgurationDetails.html
有人可以告诉我,我如何在不添加 servlet 名称来请求映射 ulr 的情况下进行操作,并告诉我名称是如何添加的。 谢谢
最佳答案
根据您的web.xml
配置文件中,您告诉您的应用程序使用 org.springframework.web.servlet.DispatcherServlet
处理匹配 <application_context>/personDetails/*
的请求的类.
前面的 URL 是您将在 Spring MVC 中使用的所有 URL 的起点。因此,如果您声明以下处理程序 @RequestMapping(value="/personAddressDetails.html")
,那么您需要调用的URL将是 <application_context>/personDetails/personAddressDetails.html
.
换句话说,您不需要将 servlet 映射前缀添加到您的 Controller 的 RequestMapping
中。注释。
关于java - 为什么 servlet 名称附加到请求的 map url 后面?是否可以有没有 Servlet 名称前缀的 URL?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37105336/