// jsp snippet
<button name="TesterButton" value="TesterButton" onClick="location.href='TesterServlet';">
Servlet Snippet of class TesterServlet
writer.println( (String)request.getParameter("TesterButton") ); // always returns null
The above servlet always returns null. Why does it return null ?
It’s working exactly as you told the code to do: changing the window location to the given URL. So, no surprises.
What you actually want should be coded as follows:
Or if you really insist in using JS for this for some reason:
Note that the use of
onClickinstead ofonclickindicates that you’re possibly reading outdated or poor HTML resources/examples.See also: