
i send the request one jsp page to another jsp than how i access the first jsp variable in the servlet? i m able to access only the second jsp page variable but not first jsp page?

Hi Friend,
Follow these steps:
1)form1.jsp:
<html> <form method="post" action="form2.jsp"> <table> <tr><td>Enter Name:</td><td><input type="text" name="name"></td></tr> <tr><td>Enter Address:</td><td><input type="text" name="address"></td></tr> <tr><td></td><td><input type="submit" value="submit"></td></tr> </table> </form> </html>
2)form2.jsp:
<html>
<form method="post" action="../GetServlet">
<table>
<tr><td>Enter Contact No:</td><td><input type="text" name="contact"></td></tr>
<tr><td>Enter Email:</td><td><input type="text" name="email"></td></tr>
<tr><td></td><td><input type="submit" value="submit"></td></tr>
</table>
<input type="hidden" name="name" value="<%=request.getParameter("name")%>">
<input type="hidden" name="address" value="<%=request.getParameter("address")%>">
</form>
</html>
3)GetServlet.java:
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class GetServlet extends HttpServlet {
public void doPost(HttpServletRequest req,HttpServletResponse res) throws ServletException,IOException {
String name=req.getParameter("name");
String address=req.getParameter("address");
String con=req.getParameter("contact");
String email=req.getParameter("email");
res.setContentType("text/html");
PrintWriter out = res.getWriter();
out.println("Name: "+name);
out.println("Address: "+address);
out.println("Contact No: "+con);
out.println("Email: "+email);
}
}
Thanks
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.