views:

358

answers:

2

I have the following in my web.xml file:

<servlet>
    <servlet-name>onBoardingUI</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
    <servlet-name>sample</servlet-name>
    <url-pattern>*.html</url-pattern>
</servlet-mapping>

<servlet-mapping>
    <servlet-name>sample</servlet-name>
    <url-pattern>*.form</url-pattern>
</servlet-mapping>

and in my sample-servlet.xml file:

 <bean id="multipartResolver"
    class="org.springframework.web.multipart.commons.CommonsMultipartResolver">

    <!-- one of the properties available; the maximum file size in bytes -->
    <!-- <property name="maxUploadSize" value="100000" /> -->
</bean>

<bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
    <property name="mappings">
        <value>
            /fileupload.form=fileUploadController
        </value>
    </property>
</bean>

<bean id="fileUploadController" class="com.wrightexpress.si.onboardingui.web.FileUploadController">
    <property name="commandClass" value="com.wrightexpress.si.onboardingui.service.UploadFile" />
    <property name="formView" value="process-file" />
    <property name="successView" value="results" />
</bean>

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

Now when I deploy the application, I get a 404 when hitting the context root. No exceptions or anything in the server log. I realized that I am setting the URL handler, but for some reason no requests are getting through. I've tried various forms of declaring the servlet-mappings in web.xml to no avail. I have a simple file upload form that has an action of fileupload.form.

Thanks!

EDIT: I have a series of jsp pages that are currently being served up via the viewResolver defined above. These stop working when I add the urlMapping bean in there. Now, I don't know how I should handle this, if I just apply a servlet-mapping of /* in the web.xml file, how do I specify in the sample-servlet.xml file which controller to tie each jsp to other than individually? Or how do I keep my web.xml like it is and only have the defined URL handler handle the fileupload.form action?

A: 

Once you start defining URL Mappings, you will need to tell spring mvc how to handle any URLs not specifically mapped. Try adding the following mapping:

/*=urlFilenameViewController

and the following bean to handle these requests:

<bean id="urlFilenameViewController" class="org.springframework.web.servlet.mvc.UrlFilenameViewController" />

The UrlFilenameViewController will pass the URI directly to the view resolver. e.g. xxx.com/index.html will get mapped to WEB-INF/jsp/index.jsp

If you need to use the full path of the URI, (e.g. xxx.com/help/index.html maps to WEB-INF/jsp/help/index.jsp)
then set the alwaysUseFullPath property on the URL Mapping

<property name="alwaysUseFullPath" value="true" />
Donal Boyle
A: 

are you sure your web.xml ist right? you have a DispatcherServlet called "onBoardingUI" but your servlet-mapping tags do look for a servlet called "sample".

shouldnt the servlet-mapping be:

<servlet>
    <servlet-name>onBoardingUI</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
    <servlet-name>onBoardingUI</servlet-name>
    <url-pattern>*.html</url-pattern>
</servlet-mapping>

<servlet-mapping>
    <servlet-name>onBoardingUI</servlet-name>
    <url-pattern>*.form</url-pattern>
</servlet-mapping>
smeg4brains