Question

I've got a problem with the parameters passed in the url.

Let say the request is: /struts/MyAction.action?param=foo%40bar.com

The action field gets the "param" field set to "foo%40bar.com", is that a bug or I am expecting too much from Struts?

My intuition tells me that I should get the value: "foo@bar.com", as for instance would happen if I passed that parameter as a POST form field.

I am using the default interceptor stack and my action class extends ActionSupport. I get the some behaviour on WebSphere6.1 & GlassFish2.1.

Thanks


Hi Again,

The problem was caused by a bug in the proxy implementation. We've written a custom proxy server that was standing in front of the web application. It was encoding the URL parameters for the second time and that's why in Struts I had %40 instead of @. Bug has been fixed now and parameters are being passed correctly.

Thanks for all your help

Was it helpful?

Solution

I don't think Struts2 is responsible for decoding the parameters, but rather the servlet container is e.g. Tomcat, Jetty, etc.

OTHER TIPS

Your intuition is right, you should be getting "foo@bar.com". With the following test of struts version 2.0.14 I could enter !@#$#$^$&%#$%& into a from and display it on another page without issue.

I tested a bare bones struts 2.0.14 application with a form that takes a string:

<s:form action="form-view.action" method="GET">
  <s:textfield label="email" name="email"/>
  <s:submit/>
</s:form>

A basic action class (note with stuts2 at this version you don't need setters/getters):

package struts2;

import com.opensymphony.xwork2.ActionSupport;

public class FormViewAction extends ActionSupport{
   public String email;
}

And a very basic display page containing:

<s:property value="email"/>

Here is the struts.xml:

<struts>
  <constant name="struts.enable.DynamicMethodInvocation" value="false" />
  <constant name="struts.devMode" value="true" />
  <package namespace="" name="example" extends="struts-default">
    <action name="form-view"  class="struts2.FormViewAction">
      <result>/form-view.jsp</result>
    </action>
  </package>
</struts>

There must be a configuration issue... Are you building with maven? Why are you using version 2.0.14 instead of 2.2.1? Just as an aside I down-graded a test application from 2.2.1 down to 2.0.14 and this took my about 5 min to do. I don't think there are any serious impediments from upgrading to the current version which will give you up to date documentation.

I ran this on Glassfish 3.0.1.

If you are not building with maven please list the jars in your library, your web.xml and struts.xml files and if possible a minimal form.jsp, display.jsp and an Action class to reproduce the issue.

What is your problem with parameters? What were you hoping that the param field would be set to?

You could write a custom type converter if you want your Action property to be converted differently to the way Struts does it.

As rado indicated, the Servlet Container is responsible for decoding the parameter values in the HttpServletRequest. If your values are not being URL decoded, then something is off.

Servlet Tutorial: Handling Form Data

First, what version of the Servlet API are you using? 2.5? 2.4? Do you have the correct XSD schema defined in your web.xml for the version you are using? Also, check that the version you are using matches the one that is provided by your application server.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top