samedi 10 octobre 2015

How can I rescure my spring web mvc app from 404 error?

Thanks for clicking my question.

I'm trying to make spring web MVC app based on XML.

The Project compiles well.
Tomcat starts without any error log.
JSP files are opened and printed well without the spring dispatcher.

But, 404 error occurs when I attach the spring dispatcher.

I coded below.

[web/WEB-INF/web.xml]

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://ift.tt/19L2NlC"
         xmlns:xsi="http://ift.tt/ra1lAU"
         xsi:schemaLocation="http://ift.tt/19L2NlC http://ift.tt/1drxgYl"
         version="3.1">
    <servlet>
        <servlet-name>dispatcher</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>/WEB-INF/applicationContext.xml</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>dispatcher</servlet-name>
        <url-pattern>/helloworld/*</url-pattern>
    </servlet-mapping>
</web-app>

[web/WEB-INF/applicationContext.xml]

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://ift.tt/GArMu6"
       xmlns:xsi="http://ift.tt/ra1lAU"
       xsi:schemaLocation="http://ift.tt/GArMu6 http://ift.tt/1jdM0fG">

       <bean name="helloWorldController" class="kr.co.jeonghoblog.HelloWorldController" />

       <bean id="handlerMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
              <property name="urlMap">
                     <map>
                            <entry key="/sayHello" value-ref="helloWorldController" />
                     </map>
              </property>
       </bean>

       <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
              <property name="prefix" value="/WEB-INF/jsp/" />
              <property name="suffix" value=".jsp" />
       </bean>
</beans>

[src/kr.co.jeonghoblog(package)/HelloworldController]

public class HelloWorldController implements Controller {
@Override
public ModelAndView handleRequest(javax.servlet.http.HttpServletRequest httpServletRequest,
                                  javax.servlet.http.HttpServletResponse httpServletResponse) throws Exception {

    return new ModelAndView("helloworld",new HashMap<>());
}
}

helloworld.jsp is located in [web/WEB-INF/jsp/]

How can I open the url: http://localhost:8080/helloworld/sayHello without 404 error?




Aucun commentaire:

Enregistrer un commentaire