1

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

Chris Ciesielski
  • 1,203
  • 2
  • 10
  • 19

4 Answers4

2

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

rado
  • 4,040
  • 3
  • 32
  • 26
1

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.

Quaternion
  • 10,380
  • 6
  • 51
  • 102
  • You should use getters and setters rather than exposing fields as public. That's just a general best practice in Java. – Steven Benitez Dec 14 '10 at 03:29
  • With struts you are supposed to do validation in a validation methods, the getter and setter should do nothing more than get/set, parameter constraints are also handled elsewhere... Classes in actions are thin so you don't need much insulation as such (and with an IDE refactoring really easy). In general it's a good idea but the way I do actions the benefits seem pretty abstract while not adding them improves readability. OT just FYI, hibernate can even allow the setting of private fields(via bytecode rewriting) talk about exotic! I agree get/set is 'best practice' but it isn't always best. – Quaternion Dec 14 '10 at 07:04
  • 1
    Hi, that isn't a form really but a link to an action in a generated email. The classpath seems to be ok and we get no worrying output in the logs. I will try the Struts 2.2.1 and see if it changes anything – Chris Ciesielski Dec 14 '10 at 15:19
  • It is a form, the generated email was in case the view was called without filling out the form. I removed the "generated email" default value and added the "display page" which I formatted incorrectly so it didn't show up previously. In the exact example above I did enter "!@#$#$^$&%#$%&" into that form, it showed the URL encoded string in the URL and displayed it correctly on the result page. – Quaternion Dec 14 '10 at 15:34
0

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.

Alex Barnes
  • 7,174
  • 1
  • 30
  • 50
0

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.

Steven Benitez
  • 10,936
  • 3
  • 39
  • 50