1 5 package com.opensymphony.webwork.util; 6 7 import com.opensymphony.webwork.views.util.UrlHelper; 8 9 import javax.servlet.http.HttpServletRequest ; 10 import javax.servlet.http.HttpServletResponse ; 11 import java.util.HashMap ; 12 import java.util.Map ; 13 14 15 20 public class URLBean { 21 23 HashMap params; 24 HttpServletRequest request; 25 HttpServletResponse response; 26 String page; 27 28 30 public void setPage(String page) { 31 this.page = page; 32 } 33 34 public void setRequest(HttpServletRequest request) { 35 this.request = request; 36 } 37 38 public void setResponse(HttpServletResponse response) { 39 this.response = response; 40 } 41 42 public String getURL() { 43 Map fullParams = null; 45 46 if (params != null) { 47 fullParams = new HashMap (); 48 } 49 50 if (page == null) { 51 if (fullParams != null) { 54 fullParams.putAll(request.getParameterMap()); 55 } else { 56 fullParams = request.getParameterMap(); 57 } 58 } 59 60 if (params != null) { 62 fullParams.putAll(params); 63 } 64 65 return UrlHelper.buildUrl(page, request, response, fullParams); 66 } 67 68 public URLBean addParameter(String name, Object value) { 69 if (params == null) { 70 params = new HashMap (); 71 } 72 73 if (value == null) { 74 params.remove(name); 75 } else { 76 params.put(name, value.toString()); 77 } 78 79 return this; 80 } 81 82 public String toString() { 83 return getURL(); 84 } 85 } 86 | Popular Tags |