webwork/src/main/webwork/view/velocity URLBean.java,1.8,1.9
[email protected] Mon, 17 Nov 2003 07:22:22 -0800
| Newsgroups | gmane.comp.java.open-symphony.cvs |
|---|---|
| Message-ID | <[email protected]> |
Update of /cvsroot/opensymphony/webwork/src/main/webwork/view/velocity
In directory sc8-pr-cvs1:/tmp/cvs-serv27499/src/main/webwork/view/velocity
Modified Files:
URLBean.java
Log Message:
URLBean fixes from Rickard
Index: URLBean.java
===================================================================
RCS file: /cvsroot/opensymphony/webwork/src/main/webwork/view/velocity/URLBean.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- URLBean.java 10 Nov 2003 00:52:31 -0000 1.8
+++ URLBean.java 17 Nov 2003 15:22:20 -0000 1.9
@@ -8,9 +8,11 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
+import javax.servlet.http.HttpUtils;
import java.util.Map;
import java.util.HashMap;
import java.util.Iterator;
+import java.util.Hashtable;
import java.net.URLEncoder;
/**
@@ -63,13 +65,11 @@
*/
public URLBean addParameter(String name, Object value)
{
- if (params == null)
- params = new HashMap();
-
if (value == null)
params.remove(name);
else
params.put(name, value.toString());
+
return this;
}
@@ -80,6 +80,24 @@
public void setRequest(HttpServletRequest req)
{
this.request = req;
+
+ // Add query parameters
+ String query = req.getQueryString();
+ if (query != null)
+ {
+ // Remove possible #foobar suffix
+ int idx = query.lastIndexOf('#');
+ if (idx != -1)
+ query = query.substring(0, idx-1);
+
+ Hashtable queryParams = HttpUtils.parseQueryString(query);
+ if (queryParams.size() > 0)
+ {
+ if (params == null)
+ params = new HashMap();
+ params.putAll(queryParams);
+ }
+ }
}
/**
@@ -101,13 +119,6 @@
*/
public String getURL()
{
- if (page == null)
- {
- // No particular page requested, so go to "same page"
- // Add query params to parameters
- params.putAll(request.getParameterMap());
- }
-
StringBuffer link = new StringBuffer();
if (page != null)
{
@@ -129,7 +140,7 @@
link.append(requestURI);
}
- if (params != null && params.size() > 0)
+ if (params.size() > 0)
{
link.append('?');
@@ -151,9 +162,17 @@
else
{
String[] values = (String[]) value;
- link.append(name);
- link.append('=');
- link.append(URLEncoder.encode(values[0]));
+
+ for (int i = 0; i < values.length; i++)
+ {
+ String val = values[i];
+ link.append(name);
+ link.append('=');
+ link.append(URLEncoder.encode(val));
+ if (i < values.length - 1)
+ link.append("&");
+ }
+
}
}
@@ -174,12 +193,6 @@
result = link.toString();
}
- // Reset params and page
- if(params.size()>0)
- {
- this.params.clear();
- }
- this.page=null;
return result;
}
@@ -187,4 +200,4 @@
{
return getURL();
}
-}
+}
-------------------------------------------------------
This SF. Net email is sponsored by: GoToMyPC
GoToMyPC is the fast, easy and secure way to access your computer from
any Web browser or wireless device. Click here to Try it Free!
https://www.gotomypc.com/tr/OSDN/AW/Q4_2003/t/g22lp?Target=mm/g22lp.tmpl