请参阅下面的代码 日志文件 2017-11-06 23:34:15 DEBUG DispatcherServlet:861 - DispatcherServlet,名称为' Spring'处理GET请求[/ Insurance1 /]%2017-11-06 23:34:15 WARN PageNotFound:1136 - 在DispatcherServlet中找不到带有URI [/ Insurance1 /]的HTTP请求的映射,名称为' Spring' %2017-11-06 23:34:15 DEBUG DispatcherServlet:996 - 已成功完成请求%
1.Dispatcher servlet:
<pre><code>
<context:component-scan base-package="Insurance1.Controller" />
<bean>
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/View/"></property>
<property name="suffix" value=".jsp"></property>
</bean>
</code> </pre>
2. Web.xml:
<pre><code>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/rootApplicationcontext.xml</param-value>
</context-param>
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<servlet>
<servlet-name>Spring</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Spring</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
</code></pre>
3.My controller
<pre><code>
@Controller
public class Helloworld {
@RequestMapping(value = { "/", "/home","/Insurance1/" }, method = RequestMethod.GET)
public String homePage(ModelMap model) {
model.addAttribute("greeting", "Hi, Welcome to mysite");
return "welcome";
}
@RequestMapping(value = "/admin", method = RequestMethod.GET)
public String adminPage(ModelMap model) {
model.addAttribute("user", getPrincipal());
return "admin";
}
</code></pre>
答案 0 :(得分:0)
@RequestMapping(value = { "/", "/home","/Insurance1/" }, method = RequestMethod.GET)
我认为,您应该将其更改为
@RequestMapping(value = { "/", "/home","/Insurance1" }, method = RequestMethod.GET)
答案 1 :(得分:0)
假设您的应用程序的上下文名称为/abc
且服务器运行的端口为XXXX
,请尝试向http://localhost:XXXX/abc/Insurance1/发送请求。只需将'XXXX'替换为运行tomcat的实际端口号,并将'abc'替换为应用程序的实际上下文。让我知道它是否有帮助。