lucky_start_izumi
lucky_start_izumi

Reputation: 2591

About spring mvc configuration

I am trying to build a web app using spring mvc. But so far, when I start server, always get 404. Could anyone please give me some suggestion about my configuration.

web.xml:

<servlet>
   <servlet-name>action</servlet-name>
   <servlet-class>
        org.springframework.web.servlet.DispatcherServlet
    </servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping> 
    <servlet-name>action</servlet-name> 
    <url-pattern>*.jsp</url-pattern>
</servlet-mapping>
 <welcome-file-list>
   <welcome-file>index.jsp</welcome-file>

action-servlet.xml:

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

These are under WEB-INF.

I have the annotation:

 @RequestMapping(value="index.jsp",method=RequestMethod.GET) 

mapping at my controller's only method. My jsp pages are under webapp/WEB-INF/jsp/. My two config files are under WEB-INF

Please give me some suggestion!!! Thank you very much!

Upvotes: 1

Views: 213

Answers (3)

Orchid
Orchid

Reputation: 223

add below segment to your web.xml It will tell where to fing the dispatcher servlet.

    <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>
        /WEB-INF/action-servlet.xml,
    </param-value>
</context-param>

Upvotes: 0

Fuser
Fuser

Reputation: 154

I'm familiar using Spring with Portlets so please forgive me if this isn't relevant, but does your controller have the following class-level annotations?

@Controller
@RequestMapping("VIEW")

For now I'd also lose the parms on your method annotation.

Upvotes: 0

Tuan Do
Tuan Do

Reputation: 26

In Spring MVC, you have to return a ModelAndView in the method with @RequestMapping anotation like this:

@RequestMapping(value="/home")
public ModelAndView goHome()
{
   ModelAndView mav = new ModelAndView("home");
   return mav;
}

The string in modelAndView is depending on your configuration in web.xml. In your situation is home.jsp page.

Upvotes: 1

Related Questions