0

I am sending a post request from a form to a redirect servlet. The servlet then write a form to its response (getWriter) object. This form contains a number of hidden fields. I use javascript to submit this form (the javascript is written to the response object as well). The target of this form is another servlet.

Now, I'm writing a filter to intercept the hidden parameters I'm sending over to the other servlet (on another server). However when I do: String[] values = req.getParameterValues(name);

I get no values for any of the parameters I put in the string "name". I cannot change the architecture of the code (not mine). I just need to get the parameters sent by the first servlet in my filter, but I keep getting null. Any help is greatly appreciated.

my first servlet code:

    PrintWriter out = response.getWriter();
    out.println("<html>");
    out.println("<head><title>redirectServlet</title></head>");

    out.println("<body>");
    out.println("<form name=\"go\" method=\"post\" action=\"http://" + 
                remotehost + "/somerep/someservlet?\">");



    out.println("<input type=hidden name=userid value=" + conn + "> ");

    out.println("<input type=hidden name=paramform value=no> ");
    out.println("<input type=hidden name=nonblocksql value=no> ");
    out.println("<input type=hidden name=recursive_load value=no> ");
    out.println("<input type=hidden name=job_seq_id value=" + jobId + ">");
    out.println("<input type=hidden name=destype value=cache> ");
    out.println("<input type=hidden name=desformat value=pdf> ");
    out.println("</form> ");

    out.println("<script language=\"JavaScript\" type=\"text/javascript\"> ");
    out.println("document.getElementById('go').submit();");
    out.println("</script>");

    out.println("</body>");
    out.println("</html>");
5
  • Difficult-to-impossible to say without seeing some code Commented Oct 31, 2011 at 20:43
  • Matt, I've updated my question with some code. This servlet will submit the form using javascript to the specified remote servlet. I want to intercept this request using a servlet filter on the remote servlet's machine/server. Commented Oct 31, 2011 at 20:52
  • 4
    You really should consider using JSPs for the HTML parts, and Servlets for the logic parts. Commented Oct 31, 2011 at 20:58
  • 1
    Out of curiosity, why aren't you just submitting an HTTP POST on behalf of the browser? The current implementation is kind of a WTF. Commented Oct 31, 2011 at 21:02
  • @MattBall I thought the same believe me! My job is just to write the filter (or to get my job done, i need to write the filter). I have no idea why they chose to do it like this...@Pilipp true its better that way, but I'm working within an established project in a framework called ADF (sux!). Anyways, thanks for your replies. Commented Nov 1, 2011 at 14:11

1 Answer 1

1

There is no element with ID go in that generated HTML. Change

out.println("<form name=\"go\" method=\"post\" action=\"http://" + 
// to
out.println("<form id=\"go\" method=\"post\" action=\"http://" + 
Sign up to request clarification or add additional context in comments.

1 Comment

Good catch, however this works in terms of calling the remote servlet...I'll change and see if it makes a difference. Thanks!: just tried..seems like it doesn't make a difference in IE. I can get the headers fine, but not the hidden parameters.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.