Issue Details (XML | Word | Printable)

Key: SPR-4407
Type: Bug Bug
Status: Resolved Resolved
Resolution: Fixed
Priority: Major Major
Assignee: Juergen Hoeller
Reporter: Gareth Webber
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
Spring Framework

<form:form> tag produces incorrect action attribute under Glassfish v2

Created: 29/Jan/08 10:19 AM   Updated: 01/Feb/08 03:21 AM
Component/s: SpringWEB
Affects Version/s: 2.0.8, 2.5.1
Fix Version/s: 2.5.2, 2.0.9

Time Tracking:
Not Specified

File Attachments: 1. File jsp-forward-test.war (4 kB)

Environment: Glassfish v2. Mac OSX 10.5

Virtual Machine: Sun JVM - 1.5


 Description  « Hide
This is a generic problem with the <form:form> tag on glassfish which has been reported as a bug in spring webflow here: http://jira.springframework.org/browse/SWF-433 but is in fact a problem in spring web.

I am migrating an application which worked fine in Tomcat but fails under glassfish.

When the action="blah" attribute of a form is generated by <form:form> tags, instead of providing the correct url e.g blah.htm?projectid=6, under gassfish the action is pointing to the jsp which is rendering the view. This means on form submission the content is sent to the view, cutting out the controller and generally fails as you would expect.

This also seems to be a problem with Jetty: http://weblogs.java.net/blog/johnsmart/archive/2007/07/spring_mvc_tile.html

I am using spring 2.5.1

Gareth

 All   Comments   Work Log   Change History   FishEye   Builds      Sort Order: Ascending order - Click to sort in descending order
Juergen Hoeller added a comment - 29/Jan/08 01:13 PM
This probably has to do with GlassFish's getRequestURI behavior...

Can you please - in the same JSP - check what request.getRequestURI() and request.getAttribute("javax.servlet.forward.request_uri") result in? Spring checks the latter first, then falling back to the former... which should work fine according to the Servlet 2.4 spec.

Juergen

Gareth Webber added a comment - 30/Jan/08 03:44 AM
OK.

The URL in my browser bar is: http://localhost:8080/tables-admin/createProject.htm

getRequestURI returns: /tables-admin/jsp/createProject.jsp
request.getAttribute("javax.servlet.forward.request_uri") returns: null

This is what I added to the JSP:

<p>1 <%= request.getRequestURI() %></p>
<p>2 <%= request.getAttribute("javax.servlet.forward.request_uri") %></p>

Glassfish is a JEE 1.5 implementation (whereas most appservers are still 1.4). It uses the 2.5 servlet spec. Could there be a change in spec, or is it a bug in the servlet container?

Gareth

Gareth Webber added a comment - 30/Jan/08 04:29 AM
Just a thought: could either

org.springframework.web.servlet.view.InternalResourceViewResolver - or -
org.springframework.web.servlet.view.JstlView

be overwriting the URI by calling the JSP in the wrong way?

Gareth

Juergen Hoeller added a comment - 30/Jan/08 04:37 AM
This is strange since Spring's InternalResourceView even checks for the presence of those attributes and exposes them itself if not present already. See InternalResourceView, line 184... You could put a breakpoint in the debugger there when running within GlassFish.

InternalResourceView's behavior should be appropriate there; this seems to work fine on all other containers. Still, something's going wrong between InternalResourceView and GlassFish there...

You could try to code a simple servlet and manually call RequestDispatcher.forward, triggering a forward to your JSP. I wonder whether the "javax.servlet.forward.request_uri" attribute is available then... This would be the ultimate test of GlassFish's raw forward behavior.

There is no relevant change in the Servlet 2.5 spec as far as I can see.

Juergen

Gareth Webber added a comment - 31/Jan/08 04:13 AM
WAR containing a simple servlet and a JSP to test RequestDispatcher forwarding behaviour. Source included.

Gareth Webber added a comment - 31/Jan/08 04:20 AM
OK. Assuming I understood you correctly (see attached WAR), here are the results.

Value in browser address bar: http://localhost:8080/jsp-forward-test/

In servlet before forward:

request.getRequestURI(): /jsp-forward-test/
request.getAttribute("javax.servlet.forward.request_uri"): null

As seen by JSP after forward

request.getRequestURI(): /jsp-forward-test/jsp/fwdTarget.jsp
request.getAttribute("javax.servlet.forward.request_uri"): /jsp-forward-test/

Gareth

Gareth Webber added a comment - 31/Jan/08 07:11 AM
OK. I set logging to FINEST on

and then click on

org.springframework.web.servlet.view - and -
org.springframework.web.util (to pick up WebUtils)

This is the log output

[#|2008-01-31T13:07:45.804+0000|FINE|sun-appserver9.1|org.springframework.web.servlet.view.InternalResourceViewResolver|_ThreadID=17;_ThreadName=httpSSLWorkerThread-8080-1;ClassName=org.springframework.web.servlet.view.AbstractCachingViewResolver;MethodName=resolveViewName;_RequestID=92451d78-020f-47dc-9561-1748c0c3ad6f;|Cached view [createProject]|#]

[#|2008-01-31T13:07:45.805+0000|FINE|sun-appserver9.1|org.springframework.web.servlet.view.JstlView|_ThreadID=17;_ThreadName=httpSSLWorkerThread-8080-1;ClassName=org.springframework.web.servlet.view.AbstractView;MethodName=render;_RequestID=92451d78-020f-47dc-9561-1748c0c3ad6f;|Rendering view with name 'createProject' with model null and static attributes {}|#]

[#|2008-01-31T13:07:45.805+0000|FINE|sun-appserver9.1|org.springframework.web.servlet.view.JstlView|_ThreadID=17;_ThreadName=httpSSLWorkerThread-8080-1;ClassName=org.springframework.web.servlet.view.InternalResourceView;MethodName=renderMergedOutputModel;_RequestID=92451d78-020f-47dc-9561-1748c0c3ad6f;|Forwarding to resource [jsp/createProject.jsp] in InternalResourceView 'createProject'|#]

I am now at a loss as I am not sure what to look at. Any ideas?

Juergen Hoeller added a comment - 31/Jan/08 05:02 PM
I've reproduced this problem on GlassFish in the meantime, and also verified that it works fine on Tomcat 6 (which is Servlet 2.5 compliant as well) - with the "javax.servlet.forward.request_uri" attribute exposed as expected on Tomcat but not on GlassFish...

I'll do some debugging to find out what the root cause is. I'll keep you posted.

Juergen

Juergen Hoeller added a comment - 31/Jan/08 05:43 PM
Apparently GlassFish gets confused by pre-exposed forward attributes, which Spring's InternalResourceView does in order to enforce the presence of those attributes even on Servlet 2.3 and misbehaving Servlet 2.4 containers (such as OC4J)...

We haven't heard of a conflict there before, hence the exposure of those attributes was done on any container. I've revised this now to skip that manual exposure on Servlet 2.5 or above, relying on the servlet container to fully implement those forward attributes itself... (which is a Servlet 2.4 spec feature anyway).

This fix should be available in tonight's 2.5.2 snapshot already (-389, available from http://static.springframework.org/downloads/nightly/snapshot-download.php?project=SPR). Feel free to give it a try...

Juergen

Gareth Webber added a comment - 01/Feb/08 03:21 AM
Just plugged the jars into my application and I seem to be back in business.

Thanks

Gareth