Spring 3: Map Page.html To Page.jsp

- 1 answer

I'm using Spring 3 and i don't know how to map somepage.htm to somepage.jsp without a controller. That is: if i go to somepage.htm, i want it to show me the jsp. But of course without redirect. I dontw want anyone to see ".jsp" only ".htm"



<bean id="viewResolver"
<property name="prefix">
<property name="suffix">



The way to do is to use the <mvc:view-controller..> tag in combination with a view resolver.

See here for more documentation:

The <mvc:view-controller..> tag maps urls to views. So if you want to map the relative url /login to a view names login you would do it by adding the following line to you webmvc-context.xml file:

<mvc:view-controller path="/login" view-name="login" />

Of course to get this to work you'll have to have a view resolve - something that maps logic names to specific views - setup in your context. In your case since you are using straight jsps for you view layer you'll want to add something like this to your configuration:

<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"/>

So with this setup if you had a jsp login.jsp located in you /WEB-INF/jsp directory then you would be able to directly reference that jsp from the url

See here for some more info on view resolvers: