0

i'm developing a J2EE App using Spring (mvc, security, etc...) and i have a problem with the mappings. I would like to redirect people who type "..../myapp" to a welcome jsp, specifically to "/myapp/welcome.html"

Previously my servlet-mapping had this config:

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

But i changed it, in order to catch the "/myapp" request. The newone that i wrote is the following:

<servlet-mapping> <servlet-name>ThreddsAdminPanel</servlet-name> <url-pattern>/*</url-pattern> </servlet-mapping> 

It works as expected but when i try to access to a page which needs an css, this error appears: "No mapping found for HTTP request with URI"

I think that if My url-pattern is /*, the servlet is catching something that doesn't belong to it although i don't know how to do it. Does anybody know a good way to do this?

Thank you

1 Answer 1

1

See this: Pretty URL Mapping with Spring 3.0

Basically, change your servlet-mapping from /* to / and then you can worry about performing the redirect.

For the redirect, you should be able to do something like this (assuming use of the mvc namespace in XML config):

<mvc:view-controller path="/myapp" view-name="redirect:/myapp/welcome.html"/> 
Sign up to request clarification or add additional context in comments.

6 Comments

FYI, if you don't already have it, add this to your XML to use the mvc namespace: xmlns:mvc="http://www.springframework.org/schema/mvc" and xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd"
Thank you for answering @superEb but my problem persists... i've replaced /* by / but the css and js files don't load. For example, "No mapping found for HTTP request with URI [/myapp/js/usersTable.js]" and into the deployed folder i can see the js folder in the root as expected.
If your static resources are deployed within your web app (i.e. WAR), then you'll also need to map those resources in Spring configuration, like <mvc:resources mapping="/myapp/js/**" location="/resources/js/" />
Yes, my resources are deployed within the war. The <mvc:resources and <mvc:view-controller that you mentioned before must be in the web.xml file?
No, in your Spring config for the servlet, e.g. "dispatcher-servlet.xml" if your servlet name is "dispatcher", or "ThreddsAdminPanel-servlet.xml" if your servlet name is "ThreddsAdminPanel". You said you're using Spring MVC, so I assume you are using Spring's DispatcherServlet for your servlet class in web.xml.
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.