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”
<servlet>
<servlet-name>Training01</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Training01</servlet-name>
<url-pattern>*.htm</url-pattern>
</servlet-mapping>
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix">
<value>/jsp/</value>
</property>
<property name="suffix">
<value>.jsp</value>
</property>
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/loginto a view names login you would do it by adding the following line to youwebmvc-context.xmlfile: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:
So with this setup if you had a jsp login.jsp located in you
/WEB-INF/jspdirectory then you would be able to directly reference that jsp from the urlwww.myapp.com/mycontenxtroot/loginSee here for some more info on view resolvers: