Vita Rara: A Life Uncommon

Parameters

I might have missed something here but when I use this code I would loose the parameters from the original request, ie. /namespace/myaction.s2?someparam=12345 would result in /namespace/myaction.s2

Here is what I came up with for forwarding the request with the parameters intact.


    	String namespace = actionInvocation.getProxy().getNamespace();
    	String actionName = actionInvocation.getProxy().getActionName();
    	String requestString = "";
    	
    	Map session = actionInvocation.getInvocationContext().getSession();
    	Map parameters = actionInvocation.getInvocationContext().getParameters();

    	int count = 0;
    	Iterator parametersItr = parameters.entrySet().iterator();
    	while (parametersItr.hasNext()) {
			Map.Entry entry = (Map.Entry) parametersItr.next();

			// add the parameter onto the request string
			Object parameterKey = entry.getKey();
			String[] parameterValue = (String[])entry.getValue();
			for(int j = 0; j < parameterValue.length; j++){
				// if it's the first parameter add a '?' else add a '&'
				requestString += (count == 0) ? "?" : "&";
				
				//get the parameter at this point
				requestString += parameterKey + "=" + parameterValue[j].toString();
			}
			count++;
		}

    	String urlGoingTo = namespace + "/" + actionName + ".s2" + requestString;


Reply

Please solve the math problem above and type in the result. e.g. for 1+1, type 2
  • Allowed HTML tags: <a> <img> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <pre> <h1> <h2> <h3>
  • Lines and paragraphs break automatically.
More information about formatting options