views:

184

answers:

3

I'm not experienced in debugging Java EE (I'm rather a javascript guy) and I need to see what HTTP POST parameters get to the server side. I put a breakpoint in a jsp file that the form is pointing its action to and now I can't find the POST content in the debug variables window.

Where are they? How can I lookup the POST in debug?

[I'd use wireshark, but it's over the https]

+1  A: 

In jsp you can use request object and call its method getParameterNames () or getParameter (String name). You can also call request.getMethod () to ensure that you obtain parameters from POST request.

<%
   if (request.getMethod().equals("POST")) {
      for (String paramName : request.getParameterNames ()) {
          String value = request.getParameter (paramName);
      }
   }
%>
John Doe
java says request.getParameterNames() is not ok to iterate on
naugtur
+1  A: 

In the breakpoint, just check the HttpServletRequest property of the JspContext instance and then check its parameterMap property.

Or do it the poor man's way by just printing them all in the JSP:

<c:forEach items="${param}" var="p">
    Param: ${p.key}=
    <c:forEach items="${p.value}" var="v" varStatus="loop">
        ${v}${loop.last ? '<br>' : ','}
    </c:forEach>
</c:forEach>

That said, you'd normally be interested in them inside a servlet class, not inside a JSP. This would indicate that you're doing some business logic inside a JSP file using using scriptlets. This is considered bad practice. Don't do that and move that raw Java code to real Java classes before it's too late. Use JSP for presentation only. You can use taglibs like JSTL to control the page flow and use EL to access backend data.

BalusC
"This is considered bad practice" - nope, this is called "not my code" :D Thanx for the answer. I won't check it out now, because I did it with a workaround, and it's over now ;)
naugtur
A: 

workaround

put action="http://localhost/posthelper.php" in Your form tag and

<pre><?php print_r($_POST); ?></pre>

in the file in apache's wwwroot

And the POST is Yours [in this case Mine :)]

naugtur
This would work if of course you have PHP support on your server. But in your case, you're looking for a solution with JSP and Java. So, your solution above won't be very helpful, would it?
Helen Neely
That's why there is "workaround" written in bold at the top of the post.
naugtur