• Post Reply Bookmark Topic Watch Topic
  • New Topic

JSP to Servlet

 
Nils Persson
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm new to Resin and Servlets.
How do I do this?
I just want to submit a form (a submitbutton and a textbox named myText)to a servlet,
and use request.getParameter("myText")to catch the textfield (and do something with the text).
and then I want to redirect to another page.
Do I save the java file as Servlet or Bean?
It is a very basic thing but I can not get it right.
How do I make the connection JSP -> Servlet -> another JSP?
Thanks.
Nils
 
Baraj Bhushan
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Nils Persson:
I'm new to Resin and Servlets.
How do I do this?
I just want to submit a form (a submitbutton and a textbox named myText)to a servlet,
and use request.getParameter("myText")to catch the textfield (and do something with the text).
and then I want to redirect to another page.
Do I save the java file as Servlet or Bean?
It is a very basic thing but I can not get it right.
How do I make the connection JSP -> Servlet -> another JSP?
Thanks.
Nils

Ans::::::::Here...........
In Servlet......Write
String Var1 = (String)request.getParameter("TextBoxName1")
String Var1 = (String)request.getParameter("TextBoxName1")
String Var1 = (String)request.getParameter("TextBoxName1")
It will get value of all the text boxes....
Then for redirecting to onother JSP write.
request.setAttribute("RefName1","ValueOfVar1");
request.setAttribute("RefName2","ValueOfVar2");
request.setAttribute("RefName3","ValueOfVar3");
getServletCofig().getServletContext().getRequestDisapatcher(/NextJspFileName.jsp).forward(request,response);
Then in receiving JSP write....
String Var1 = (String)request.getAttribute("RefName1")
String Var2 = (String)request.getAttribute("RefName2")
String Var3 = (String)request.getAttribute("RefName3")
Then Do whatever you want ..........
 
Nils Persson
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanx for a fast reply.
Ok, but from the JSP page how do the page know to which Servlet it is supposed to go to.
Do I write it in the forms action="???".
Suppose I want a user type his name and then submit.
I then go to the servlet and in the servlet I want to open a text file and save the users name.
Then redirect...
The remaining problem is how do the page know to which Servlet it is supposed to go to.
Thanks
/Nils
 
Mike Curwen
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In your deployment descriptor, you specify a servlet alias. This will map an actual class file to a name.

In the action tag of your form, you'd place the servlet alias.

You can also use it directly in an url (http://localhost:8080/.../servletalias?param1=val1¶m2=val2
here is a short example. note that the servlet class file is named serPickup.class. Note also the double-indirection. serPickup.class is given the name PickUp which is referenced by the alias (url-pattern) pickup.
This file is named web.xml, and placed in the WEB-INF directory
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!