tags:

views:

20

answers:

2

Hi, i am working on a simple jsp page, it contain 2 textbox firstname and lastname,and a ok button, when textbox is filled and button is clicked, I need to get values of firstname and lastname and post to url http://mydomain/firstname/lastname, how to do this?

A: 

var firstName = document.getElementById("id of firstname textbox ").value;

var lastName =document.getElementById("id of secondname textbox ").value;

http://yourURL?fn=firstName&ln=lastName

I think above code can help you in implementing what you want.

Anil Vishnoi
+1  A: 

Let the form submit to a Servlet which sends a redirect to the particular URL. E.g. in JSP:

<form action="servletURL" method="post">
    <input name="firstname">
    <input name="lastname">
    <input type="submit" value="OK">
</form>

With the following in doPost() method of a servlet mapped on url-pattern of /servletURL:

String firstname = request.getParameter("firstname");
String lastname = request.getParameter("lastname");
response.sendRedirect(firstname + "/" + lastname);

This will end up in the desired URL.

BalusC