0

I have created one jsp form which contains the username textfield. On the click of submit button it pass on to servlet and read parameter and display on the screen.

I want to generate a querystring of username with the url.

Can anyone tell me how can i do that??

2
  • It's not displaying the querystring of the username entered in the jsp page. Is it possible?? I have used the get form method then too?? Commented Mar 19, 2012 at 9:16
  • You need to go and read a basic JSP/HTML forms tutorial. You don't build query strings yourself, you let the browser do it. Commented Mar 19, 2012 at 9:53

1 Answer 1

1

The following example will add the username field in the querystring of the request URL.

<form action="servletURL">
    <input type="text" name="username" />
    <input type="submit" />
</form>

Note that there's no method. It defaults to GET already, which means that all form data is passed by URL.

If you still don't see the querystring in the request URL, then it means that your servlet is performing a redirect after submit.

response.sendRedirect("result.jsp");

The enduser will then see the redirected URL in browser address bar instead. If you don't include the querystring in the redirect URL, then the enduser will indeed not see it at all.

You should either be doing a forward() instead,

request.getRequestDispatcher("/WEB-INF/result.jsp").forward(request, response);

or append the query string yourself:

response.sendRedirect("result.jsp?" + request.getQueryString());
Sign up to request clarification or add additional context in comments.

Comments

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.