当前位置: 首页 > 知识库问答 >
问题:

我的主页不适用于Spring mvc Web应用程序。当我运行应用程序时,我收到404错误。请

钱运浩
2023-03-14

请参见日志文件2017-11-06 23:34:15下面的代码调试DispatcherServlet:861 -名为“Spring”的DispatcherServlet处理[/Insurance1/]的GET请求17-11-06 23:34:15 WARN page not found:1136-在名为“Spring”的DispatcherServlet中找不到具有URI[/insurace 1/]的HTTP请求的映射17-11-06 23:34

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>

共有2个答案

郎鹤龄
2023-03-14

假设您的应用程序的上下文名称是< code>/abc,您的服务器运行的端口是< code>XXXX,只需尝试向http://localhost:XXXX/ABC/保险1/发送请求。只需用运行tomcat的实际端口号替换“XXXX ”,用应用程序的实际上下文替换“abc”。让我知道它是否有帮助。

璩慎之
2023-03-14
@RequestMapping(value = { "/", "/home","/Insurance1/" }, method = RequestMethod.GET)

我认为,你应该把它改成

@RequestMapping(value = { "/", "/home","/Insurance1" }, method = RequestMethod.GET)
 类似资料: