View Single Post
  #11 (permalink)  
Old 08-22-2009, 09:10 PM
rahultaneja7 rahultaneja7 is offline
Member
 
Join Date: Jul 2009
Posts: 7
Rep Power: 0
rahultaneja7 is on a distinguished road
Default How to put value in Servlet's HTML textbox?
Hello sir, I have one query of Servlet

Below is the code of welcome page which include 2 textbox in which user
Will put value1 and value2.
Code:
<html>
<body>

<form action="Add" method="get">
Value1 <input type="text" name="t1" /><br>
Value2 <input type="text" name="t2" /><br>


<input type="submit" name="b1" value="click" />
</form>
</body>
</html>
After clicking on the submit button this HTML page would be redirected to Servlet (Add.java). The code of Servlet Add is given below
Code:
import java.io.*;
import javax.servlet.*;

public class Add extends HttpServlet {
 	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		response.setContentType("text/html");
		PrintWriter out = response.getWriter();
Int a=0,b=0,c=0;
String st1=request.getParamater(“t1”);
a =Integer.parseInt(st1);
 String st1=request.getParamater(“t2”);
b =Integer.parseInt(st2);
c=a+b;

out.println(“<html><body><form>”);
out.println(“Addition Result: <input type=\”text\” name=\”textbox1\” value=\”\”>”);
out.println(“</html></body></form>”);
}
}
This Add servlet includes the code of addition of those two values which was given by the user in welcome page. My query is how can we put the value of int variable c (c=a+b in the textbox named textbox1? Or how can we give the value of any variable to the attribute (value) of textbox?

Thanks
Hope you will reply as soon as possible.
Reply With Quote