This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes JSP and the fly likes Problem passing jsp:param Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Problem passing jsp:param" Watch "Problem passing jsp:param" New topic
Author

Problem passing jsp:param

Deb Sadhukhan
Ranch Hand

Joined: Nov 05, 2003
Posts: 67
How can I pass a string as jsp:param value in jsp:include containing + char?



Problem I'm facing is toJsp.jsp is receiving the parameter as "select col3 1 from tab", + char is replaced by space.

App is hosted on websphere.

Thanks


_ __ _ __ _ __ _<br />SCJP 1.4 (95%) | SCWCD 1.4 (79%)<br />Artificial intelligence is no match for natural stupidity.
Schandha Ravi
Ranch Hand

Joined: Oct 20, 2007
Posts: 167
Hi,

I don't know why there is a problem. THe code which you posted worked perfectly fine for me. I just replace <jsp:include> to <jsp:forward> but I believe that should not pose any problem. I printed the value of the parameter in servlet and I got "+" printed.

I did this on weblogic server. But I'm sure this is not container dependent.


Thanks & Regards, SK
SCJP 5.0, DB2 - 800, DB2 - 803, SCDJWS (On the way)
Deb Sadhukhan
Ranch Hand

Joined: Nov 05, 2003
Posts: 67
I cannot do jsp:forward as the logic demands jsp:include. Believe me, I'm also surprised by this problem.

I'm running on WebSphere.
Steve Luke
Bartender

Joined: Jan 28, 2003
Posts: 4163
    
  21

The plus sign is considered a place holder for the space character. The jsp:param will encode the URL for you so it shouldn't be a problem (the + will be encoded to %2B).

How are you accessing the values? It looks to me like it is being passed through a decoder once to often The request.getParameter(parameterName) will decode it for you first. Are you doing any other option that also attempts to decode the URL parameter?


Steve
Deb Sadhukhan
Ranch Hand

Joined: Nov 05, 2003
Posts: 67
I'm doing request.getParameter(<parmName>) to get back the param value. What other way value can be decoded? I don't think I'm decoding more than once. I think it's not encoding to start with.

Just to be clear, I'm testing using WebSphere 5.1 test server.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60732
    
  65

Interesting.

I wrote a little test case and it appears that there are discrepancies with how the containers handle this.

Under Tomcat, the value is properly encoded and the + makes it through unscathed. Under Resin however, the value is not encoded and the plus is interpreted as an encoded space.

Which is the bug?

Let me dig into the JSP Spec and see...


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Steve Luke
Bartender

Joined: Jan 28, 2003
Posts: 4163
    
  21

Originally posted by Deb Sadhukhan:
I'm doing request.getParameter(<parmName>) to get back the param value. What other way value can be decoded? I don't think I'm decoding more than once.


Not sure if you were passing the value directly throuh URLDecoder.decode() or if you were using some other layer that also decoded. Looks as though not.

Originally posted by Deb Sadhukhan:
I think it's not encoding to start with.


That also could be the case ... see below

Originally posted by Deb Sadhukhan:
Just to be clear, I'm testing using WebSphere 5.1 test server.


What version of the JSP spec does WebSphere 5.1 support? JSP 2.0 says the jsp:param must URLEncode the parameter, whereas older versions of the spec do not say so. You may have to pass the parameter like:


But this code would break for any server that does support the JSP 2.0 spec because the result would be double encoded...
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60732
    
  65

Section JSP.5.6:
The parameter names and values specified should be left unencoded by the
page author. The JSP container must encode the parameter names and values
using the character encoding from the request object when necessary. For
example, if the container chooses to append the parameters to the URL in the
dispatchedrequest,boththenamesandvaluesmustbeencodedasperthecontent
typeapplication/x-www-form-urlencoded in the HTML specification.
So the Tomcat behavior is correct and the Resin behavior (and apparently Websphere) are not.
Steve Luke
Bartender

Joined: Jan 28, 2003
Posts: 4163
    
  21

Originally posted by Bear Bibeault:
Section JSP.5.6: So the Tomcat behavior is correct and the Resin behavior (and apparently Websphere) are not.


For JSP 2.0. For JSP 1.2 this behavior was not defined (JSP.4.4-4.6 for in the JSP 1.2 spec for applicable paragraphs). So if the versions of WebSphere and Resin in question don't claim to be JSP 2.0 containers the behavior isn't a bug.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60732
    
  65

Resin 3 is JSP 2 compliant, so it's definitely a bug there. If I'm not mistaken, WebSphere 5 is JSP 1.x.
Deb Sadhukhan
Ranch Hand

Joined: Nov 05, 2003
Posts: 67
WebSphere 5 is JSP 1.2. So that's the issue here. Value is not encoded to start with.

Thanks much for the help!
 
Consider Paul's rocket mass heater.
 
subject: Problem passing jsp:param
 
Similar Threads
can any body tell how to store check box value in session
fragment was not found error
Request/Translation time confusion
how to get object of this below chart and write in to pdf here strXMl is string of xml
JSP include param - problems with multiple include from same page