简体   繁体   中英

My home page not working for spring mvc web app.When I am running the application I am getting 404 error.Please

Please see the code below log files 2017-11-06 23:34:15 DEBUG DispatcherServlet:861 - DispatcherServlet with name 'Spring' processing GET request for [/Insurance1/]%2017-11-06 23:34:15 WARN PageNotFound:1136 - No mapping found for HTTP request with URI [/Insurance1/] in DispatcherServlet with name 'Spring'%2017-11-06 23:34:15 DEBUG DispatcherServlet:996 - Successfully completed request%

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>
@RequestMapping(value = { "/", "/home","/Insurance1/" }, method = RequestMethod.GET)

我认为,您应该将其更改为

@RequestMapping(value = { "/", "/home","/Insurance1" }, method = RequestMethod.GET)

Assuming your application's context name is /abc and the port on which your server is running is XXXX , just try to send request to http://localhost:XXXX/abc/Insurance1/ . Just replace 'XXXX' with the actual port number on which tomcat is running and replace 'abc' with the actual context of the application. Let me know whether it helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM