Spring MVC - jsp not rendering - java

I'm just starting with Spring MVC trying to create a new project, and came accross an issue for which no manual or tutorial seems to help...
I have set up a simple application with no logic, just trying to get Spring configured properly. The controller just returns the name of a view to be displayed, but the view resolver is not rendering the jsp, and returning a 404 error....
Any help is greatly appreciated.
My web.xml is:
<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<servlet>
<servlet-name>openstats</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>openstats</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
<display-name>OpenStats API Server</display-name>
</web-app>
An my openstats-servlet.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
<context:component-scan base-package="org.openstats.api.controller"/>
<!-- Enable to request mappings PER METHOD -->
<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"/>
<!-- Enable annotated POJO #Controller -->
<bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping"/>
<!-- Define the view resolver to use jsp files within the jsp folder -->
<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>/jsp/</value></property>
<property name="suffix"><value>.jsp</value></property>
</bean>
</beans>
The controller itself has no logic whatsoever, it's simply:
#Controller
public class ProductController {
#RequestMapping(value = "/products.do", method = RequestMethod.GET)
public ModelAndView listProducts(HttpServletRequest request) {
ModelAndView model = new ModelAndView("index");
return model;
}
}
The controller is reached, the issue is when attempting to render...
I set up log4j in debug, and this is part of what I get:
02:08:19,702 DEBUG
DispatcherServlet:1094 - Testing handler adapter
[org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter#397b6074]
02:08:19,803 DEBUG
HandlerMethodInvoker:134 - Invoking
request handler method: public org.springframework.web.servlet.ModelAndView
org.openstats.api.controller.ProductController.listProducts(javax.servlet.http.HttpServletRequest)
02:08:19,833 DEBUG
DefaultListableBeanFactory:1367 -
Invoking afterPropertiesSet() on bean
with name 'index' 02:08:19,876 DEBUG
InternalResourceViewResolver:81 -
Cached view [index] 02:08:19,877 DEBUG
DispatcherServlet:1181 - Rendering
view
[org.springframework.web.servlet.view.JstlView:
name 'index'; URL [/jsp/index.jsp]] in
DispatcherServlet with name
'openstats' 02:08:19,877 DEBUG
JstlView:240 - Rendering view with
name 'index' with model {} and static
attributes {} 02:08:19,923 DEBUG
JstlView:234 - Forwarding to resource
[/jsp/index.jsp] in
InternalResourceView 'index'
02:08:19,926 DEBUG
DispatcherServlet:955 -
DispatcherServlet with name
'openstats' determining Last-Modified
value for [/api-server/jsp/index.jsp]
02:08:19,927 DEBUG
DispatcherServlet:1054 - Testing
handler map
[org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping#440c4cee]
in DispatcherServlet with name
'openstats' 02:08:19,928 DEBUG
DefaultAnnotationHandlerMapping:179 -
No handler mapping found for
[/jsp/index.jsp] 02:08:19,929 DEBUG
DispatcherServlet:962 - No handler
found in getLastModified 02:08:19,937
DEBUG DispatcherServlet:781 -
DispatcherServlet with name
'openstats' processing request for
[/api-server/jsp/index.jsp]
02:08:19,938 DEBUG
DispatcherServlet:843 - Bound request
context to thread: GET
/api-server/products.do HTTP/1.1
My jsp folder is right within "webapp" and the index.jsp file exists.
Thanks in advance.

I do have the same problem with Spring 3.x.
Any progress so far?
EDIT:
I figured it out myself :-) I used the following servletmapping:
<servlet-mapping>
<servlet-name>spring-frontcontroller</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
Editing the url-pattern to e.g. *.do fixes the problem of not rendering the JSP.
But this leaves the question how this is possible with your url-pattern.

Does your web.xml define index.jsp in the welcome-file-list, if so it may be getting overridden. Try changing the jsp name to products.jsp.
e.g.
#Controller
public class ProductController {
#RequestMapping(value = "/products.do", method = RequestMethod.GET)
public String handleRequest() {
return "products";
}
}

doesn't your .jsp and your .do conflict? since a file cannot end with both .jsp and .do .. therefore it will never resolve... so you should get rid of .jsp or change your url pattern to /*

Changing
import org.springframework.web.servlet.ModelAndView;
by
import org.springframework.web.portlet.ModelAndView;
Works in my case.

Related

Overriding spring 3.1 properties in websphere console

I a'm developing web application for websphere 7.0. It's XML based spring 3.1 application. In my application I use many configuration properties files. But in production we don't have access to file system on websphere server, so we don't have access to spring or properties files or web.xml. Therefore we need override properties from configuration files in websphere administration console. But also we need programmatic access to resolved values of some properties overrided by administrator.
I've found that context:property-placeholder resolve both context parmeters and entry-env from web.xml and override properties from file as it should be in my application, but I don't know how to get properties programatically from context:property-placeholder(it's new PropertySourcesPlaceholderConfigurer).
And in my case I could not get util:properties to be overrided by context parameters or entry-env values. As and PropertyPlaceholderConfigurer.
Also I can't edit Context parameters from websphere administration console. I didn't find this functionality and google doesn't give answers. In console I can edit only servlet initialization parameters or entry-env values.
My situation:
web.xml:
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/webappconf.xml</param-value>
</context-param>
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<servlet>
<servlet-name>springServlet</servlet-name>
<servlet-class>org.springframework.web.context.support.HttpRequestHandlerServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>springServlet</servlet-name>
<url-pattern>/springServlet</url-pattern>
</servlet-mapping>
<env-entry>
<env-entry-name>AA.AA</env-entry-name>
<env-entry-type>java.lang.String</env-entry-type>
<env-entry-value>Override AA.AA</env-entry-value>
</env-entry>
webappconf.xml
any properties resolver definition
<bean id="springService" class="ru.test.krp.SpringService">
<property name="a" value="${AA.AA}" />
<property name="b" value="${BB.BB}" />
<property name="c" value="${CC.CC}" />
<property name="config" ref="any refrence to properties for access from code"/>
</bean>
<bean id="springServlet" class="ru.test.krp.SpringServlet">
<property name="springService" ref="springService"></property>
</bean>
SpringService.java
public class SpringService {
private String a;
private String b;
private String c;
private Properties config;
// getter/setter pairs
I will appreciate any help or ideas.
You can put your configuration properties files into shared libraries. Library shoud be attached to your application.
All that you need to it's only how to reread new configuration.

configuring annotations in Springmvc

I am having below error when running my springmvc application. In my controller file I have used annotation to map viewAll.view to displagy inventory/ListAll.jsp but this doesn't seem to be working.
I can see message "In ViewDVDController.viewAll()" in the console using sysout in the controller file.
Please can you advise if i am missing some mappings?
Error:
HTTP Status 404 - /SpringMVC/views/inventory/viewAll.jsp
--------------------------------------------------------------------------------
type Status report
message /SpringMVC/views/inventory/viewAll.jsp
description The requested resource (/SpringMVC/views/inventory/viewAll.jsp) is not available.
--------------------------------------------------------------------------------
Apache Tomcat/7.0.29
index.html
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Highview DVD Management</title>
</head>
<body>
<p> This DVD Management Model contains the following modules</p>
<ul>
<li>View All DVDs </li>
<li>Add a DVD </li>
</ul>
</body>
</html>
ViewDVDController.java
#Controller
public class ViewDVDController extends MultiActionController {
public ViewDVDController(){
System.out.println("In ViewDVDController()");
}
#Autowired
private InventoryManager manager;
public InventoryManager getManager(){
return manager;
}
public void setManager(InventoryManager manager){
this.manager=manager;
}
#RequestMapping(value="viewAll.view", method=RequestMethod.GET)
public ModelAndView viewAll() throws Exception {
System.out.println("In ViewDVDController.viewAll()");
Collection<DVDInfo> all = manager.getAll();
return new ModelAndView("ListAll","catalog",all);
}
}
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
<display-name>Spring MVCDemo</display-name>
<servlet>
<servlet-name>spring</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>spring</servlet-name>
<url-pattern>/inventory/*</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
</web-app>
spring-servlet.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:cotext="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">
<mvc:annotation-driven/>
<cotext:component-scan base-package="springmvc"/>
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/views/inventory/"/>
<property name="suffix" value=".jsp" />
</bean>
</beans>
log4j Log:
22:31:38,370 DEBUG ctory.support.DefaultListableBeanFactory: 430 - Creating instance of bean 'org.springframework.web.servlet.view.DefaultRequestToViewNameTranslator'
22:31:38,372 DEBUG ctory.support.DefaultListableBeanFactory: 458 - Finished creating instance of bean 'org.springframework.web.servlet.view.DefaultRequestToViewNameTranslator'
22:31:38,372 DEBUG gframework.web.servlet.DispatcherServlet: 647 - Unable to locate RequestToViewNameTranslator with name 'viewNameTranslator': using default [org.springframework.web.servlet.view.DefaultRequestToViewNameTranslator#1a0b94d]
22:31:38,372 DEBUG ctory.support.DefaultListableBeanFactory: 245 - Returning cached instance of singleton bean 'viewResolver'
22:31:38,373 DEBUG ctory.support.DefaultListableBeanFactory: 430 - Creating instance of bean 'org.springframework.web.servlet.support.SessionFlashMapManager'
22:31:38,376 DEBUG ctory.support.DefaultListableBeanFactory: 458 - Finished creating instance of bean 'org.springframework.web.servlet.support.SessionFlashMapManager'
22:31:38,377 DEBUG gframework.web.servlet.DispatcherServlet: 709 - Unable to locate FlashMapManager with name 'flashMapManager': using default [org.springframework.web.servlet.support.SessionFlashMapManager#16c14c0]
22:31:38,377 DEBUG gframework.web.servlet.DispatcherServlet: 523 - Published WebApplicationContext of servlet 'spring' as ServletContext attribute with name [org.springframework.web.servlet.FrameworkServlet.CONTEXT.spring]
22:31:38,377 INFO gframework.web.servlet.DispatcherServlet: 463 - FrameworkServlet 'spring': initialization completed in 804 ms
22:31:38,377 DEBUG gframework.web.servlet.DispatcherServlet: 136 - Servlet 'spring' configured successfully
22:31:38,383 DEBUG gframework.web.servlet.DispatcherServlet: 819 - DispatcherServlet with name 'spring' processing GET request for [/SpringMVC/inventory/viewAll.view]
22:31:38,385 DEBUG .annotation.RequestMappingHandlerMapping: 213 - Looking up handler method for path /viewAll.view
22:31:38,387 DEBUG .annotation.RequestMappingHandlerMapping: 220 - Returning handler method [public org.springframework.web.portlet.ModelAndView springmvc.presentation.ViewDVDController.viewAll() throws java.lang.Exception]
22:31:38,388 DEBUG ctory.support.DefaultListableBeanFactory: 245 - Returning cached instance of singleton bean 'viewDVDController'
22:31:38,390 DEBUG gframework.web.servlet.DispatcherServlet: 902 - Last-Modified value for [/SpringMVC/inventory/viewAll.view] is: -1
In ViewDVDController.viewAll()
siz of the collection is 2
22:31:38,413 DEBUG ctory.support.DefaultListableBeanFactory:1498 - Invoking afterPropertiesSet() on bean with name 'viewAll'
22:31:38,413 DEBUG gframework.web.servlet.DispatcherServlet:1178 - Rendering view [org.springframework.web.servlet.view.JstlView: name 'viewAll'; URL [/views/inventory/viewAll.jsp]] in DispatcherServlet with name 'spring'
22:31:38,413 DEBUG pringframework.web.servlet.view.JstlView: 371 - Added model object 'modelAndView' of type [org.springframework.web.portlet.ModelAndView] to request in view with name 'viewAll'
22:31:38,413 DEBUG pringframework.web.servlet.view.JstlView: 371 - Added model object 'org.springframework.validation.BindingResult.modelAndView' of type [org.springframework.validation.BeanPropertyBindingResult] to request in view with name 'viewAll'
22:31:38,417 DEBUG pringframework.web.servlet.view.JstlView: 236 - Forwarding to resource [/views/inventory/viewAll.jsp] in InternalResourceView 'viewAll'
22:31:38,420 DEBUG gframework.web.servlet.DispatcherServlet: 913 - Successfully completed request
Finally, I got my answer.
I was importing wrong ModelAndView Class
(org.springframework.web*.portlet.*ModelAndView) instead of org.springframework.web.*servlet.*ModelAndView in the controller file.
In what package is ViewDVDController in? Beware that the value of base-package (in cotext:component-scan) must match your package name.

Trouble getting mapping to work

I'm using Spring 3.0.5. None of my annotated controllers are getting recognized. I have XML for my application …
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.springframework.org/schema/beans"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<mvc:resources mapping="/static/**" location="/static/"/>
<mvc:annotation-driven/>
<context:component-scan base-package="com.myco.systems.leadsmonitor"/>
My static assets are getting picked up fine. But I'm getting a 404 when I try and reach an annotated controller …
package com.myco.systems.leadsmonitor.web.controller;
#Controller
public class HomeController {
…
#RequestMapping("/")
public void index(Model model) {
model.addAttribute("latestLeadTime", MonitorStatistics.getInstance().getLatestLeadCreationTime());
model.addAttribute("lastDBCheck", MonitorStatistics.getInstance().getLastDBCheck());
}
What else do I need to do to get my controllers picked up by Spring? Thanks, - Dave
I think the reason you are getting a 404 is because the view is not being resolved in the contoller method. By default a void return type is mapped using to a view name based on the URI, in your case since the path is "/", it probably gets resolved to "", which does not get mapped to any logical view.
Can you try a couple of things:
Start in a debug mode and see if your request is actually coming to the RequestMapping method
If it is, can you explicitly return a view name from your method and see if this view name is getting resolved to a correct view(assuming that you have a view resolver registered)
You should check both URL mappings in web.xml and view resolution configuration in your spring configuration.
One good resource is Spring By Example.org
see: http://www.springbyexample.org/examples/simple-spring-mvc-form-annotation-config-webapp.html
Another one are the tutorials available in SpringSource ToolSuite (STS), where they walk you through creating a Spring MVC web application. Those tutorials usually include the UrlRewriteFilter from tuckey.org
e.g. servlet maps to /app, then add this servlet filter
<!-- Enables clean URLs with JSP views e.g. /welcome instead of /app/welcome -->
<filter>
<filter-name>UrlRewriteFilter</filter-name>
<filter-class>org.tuckey.web.filters.urlrewrite.UrlRewriteFilter</filter-class>
<!-- <init-param>-->
<!-- <param-name>logLevel</param-name>-->
<!-- <param-value>DEBUG</param-value>-->
<!-- </init-param>-->
</filter>

Spring 3 simple extentionless url mappings with annotation-based mapping - impossible?

I'm using Spring 3, and trying to set up a simple web-app using annotations to define controller mappings. This seems to be incredibly difficult without peppering all the urls with *.form or *.do
Because part of the site needs to be password protected, these urls are all under /secure. There is a <security-constraint> in the web.xml protecting everything under that root. I want to map all the Spring controllers to /secure/app/.
Example URLs would be:
/secure/app/landingpage
/secure/app/edit/customer/{id}
each of which I would handle with an appropriate jsp/xml/whatever.
So, in web.xml I have this:
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/secure/app/*</url-pattern>
</servlet-mapping>
And in despatcher-servlet.xml I have this:
<context:component-scan base-package="controller" />
In the Controller package I have a controller class:
package controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;
import javax.servlet.http.HttpServletRequest;
#Controller
#RequestMapping("/secure/app/main")
public class HomePageController {
public HomePageController() { }
#RequestMapping(method = RequestMethod.GET)
public ModelAndView getPage(HttpServletRequest request)
{
ModelAndView mav = new ModelAndView();
mav.setViewName("main");
return mav;
}
}
Under /WEB-INF/jsp I have a "main.jsp", and a suitable view resolver set up to point to this. I had things working when mapping the despatcher using *.form, but can't get anything working using the above code.
When Spring starts up it appears to map everything correctly:
13:22:36,762 INFO main annotation.DefaultAnnotationHandlerMapping:399 - Mapped URL path [/secure/app/main] onto handler [controller.HomePageController#2a8ab08f]
I also noticed this line, which looked suspicious:
13:25:49,578 DEBUG main servlet.DispatcherServlet:443 - No HandlerMappings found in servlet 'dispatcher': using default
And at run time any attempt to view /secure/app/main just returns a 404 error in Tomcat, with this log output:
13:25:53,382 DEBUG http-8080-1 servlet.DispatcherServlet:842 - DispatcherServlet with name 'dispatcher' determining Last-Modified value for [/secure/app/main]
13:25:53,383 DEBUG http-8080-1 servlet.DispatcherServlet:850 - No handler found in getLastModified
13:25:53,390 DEBUG http-8080-1 servlet.DispatcherServlet:690 - DispatcherServlet with name 'dispatcher' processing GET request for [/secure/app/main]
13:25:53,393 WARN http-8080-1 servlet.PageNotFound:962 - No mapping found for HTTP request with URI [/secure/app/main] in DispatcherServlet with name 'dispatcher'
13:25:53,393 DEBUG http-8080-1 servlet.DispatcherServlet:677 - Successfully completed request
So... Spring maps a URL, and then "forgets" about that mapping a second later? What is going on?
Thanks.
I have exactly the same problem as you. The way to set 'alwaysUseFullPath' is pretty straightforward. My conf file is as following:
<bean
class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping"
p:order="3" > <!-- a higher value meaning greater in terms of sorting. -->
<property name="alwaysUseFullPath" value="true" />
<property name="interceptors">
<list>
<ref local="myInterceptor" />
</list>
</property>
</bean>
<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
<property name="alwaysUseFullPath" value="true" />
</bean>
Ah. As usual, found the answer after posting the question :-)
Changing the RequestMapping annotation to just /main fixes the problem. The documentation is not very clear on how all this is specified.
Put something like this in your #Configuration class:
#Bean(autowire = Autowire.BY_TYPE)
public AnnotationMethodHandlerAdapter handlerAdapter(){
final AnnotationMethodHandlerAdapter annotationMethodHandlerAdapter = new AnnotationMethodHandlerAdapter();
annotationMethodHandlerAdapter.setAlwaysUseFullPath(true);
return annotationMethodHandlerAdapter;
}

Introducing Spring MVC

I'd like to introduce Spring MVC to an application that has up till now used simple direct access to JSP files i.e www.example.com/login.jsp which contains the business logic and presentation details.
I'd like to strip out the business logic and keep only the presentation in the JSP. To do this, I've moved the jsp file from webapp/login.jsp to webapp/WEB-INF/jsp/login.jsp and then mapped all urls with the pattern *.jsp to Spring's DispatchServlet which goes to a Controller and then a view which (should) forward to /WEB-INF/jsp/login.jsp.
The web.xml looks like this:
<servlet>
<servlet-name>springapp</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>springapp</servlet-name>
<url-pattern>*.jsp</url-pattern>
</servlet-mapping>
springapp-context.xml
<bean id="urlFilenameViewController" class="org.springframework.web.servlet.mvc.UrlFilenameViewController"/>
<bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="mappings">
<value>
/*.jsp=urlFilenameViewController
</value>
</property>
</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"></property>
</bean>
However, the fundamental problem with this is that I'm mapping external URL requests ending in .jsp to internal web requests that also map to .jsp. The internal .jsp request then goes through the DispatchServlet for a second time which returns an error as it cannot find anything to handle the request:
WARN - DispatcherServlet.noHandlerFound(1077) | No mapping found for HTTP request with URI [/myapp/WEB-INF/jsp/login.jsp] in DispatcherServlet with name 'springapp'
Given that I cannot change the external URLs, is there a way to get round this issue when mapping external file types to the same internal file type?
We address this in our application by using a different pattern for request URLs (*.htm instead of *.jsp). This avoids the problem and it is good practice anyway because there may not be a 1-to-1 relationship between a URL and a JSP.
I suggest you:
map Spring MVC requests to a different pattern ( e.g *.do);
use a UrlRewriteFilter or your application server's url rewrite functionality to map *.jsp calls to *.do;
I'm not sure how to tell Spring to ignore its internal requests for JSP files, but intercept other JSP requests. Why don't you keep your old jsps, but just have them forward to a controller. E.g. "page.jsp":
<%# taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
<c:redirect url="/page.htm" />
This way, you can keep your old URLs intact, but the only function is to redirect to the controllers.

Categories