struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ZHENG Zhong <>
Subject How to retrieve parameters passed via GET method?
Date Sat, 27 Nov 2004 19:37:05 GMT

Hi all, here is a newbie's question:

For example, i have a page called accountList.jsp, which displays an account list of a certain
customer. Each account has an ID as its primary key. Customer may click on the "Close" hyperlink
to close an account. The hyperlink is like this: 

<a href="">Close</a>

As you may see, the parameter accountId is passed via the GET method.

In my Struts configuration file, an action element is defined as the following: 
<action    path="/closeAccount"    type="org.apache.struts.actions.ForwardAction"    parameter="/closeAccount.jsp"

When customer clicks on the hyperlink, ActionServlet receives the HTTP request, pre-processes
it and forwards it to ForwardAction, who will simply forward the request to closeAccount.jsp.
That page then asks customer to confirm the operation ("are you sure that you want to close
account No. 100?"). The problem is, ActionServlet seems to have modified the request, so in
my closeAccount.jsp, i cannot retrieve the accountId parameter: request.getAttribute("accountId")
returns null.

I dumped the contents in the HTTP request that closeAccount.jsp receives. They look like this:

javax.servlet.forward.request_uri = /badba/ javax.servlet.forward.context_path
= /badba javax.servlet.forward.servlet_path = / javax.servlet.forward.query_string
= accountId=100 org.apache.struts.action.mapping.instance = ActionConfig[path=/closeAccount,parameter=/closeAccount.jsp,scope=session,type=org.apache.struts.actions.ForwardAction
org.apache.struts.action.MODULE = org.apache.struts.config.impl.ModuleConfigImpl@2b249   

In my web.xml file, i defined a security-constraint element to prevent customer from visiting
JSP pages directly, so every request must pass through ActionServlet, and parameters passed
via GET method will always be modified before the request arrives to a JSP page. The question
is: how to retrieve those parameters in my JSP page? Using request.getAttribute("javax.servlet.forward.query_string")
to get the value accountId=100 and then parsing the String seems to be a very stupid method.

Thanks in advance for your help.




Do You Yahoo!?
  • Unnamed multipart/alternative (inline, 8-Bit, 0 bytes)
View raw message