Win a copy of Zero to AI - A non-technical, hype-free guide to prospering in the AI era this week in the Artificial Intelligence and Machine Learning forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Paul Clapham
  • Bear Bibeault
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Jj Roberts
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • salvin francis
  • Scott Selikoff
  • fred rosenberger

JSP to Servlet

 
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
 
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
 
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
 
He puts the "turd" in "saturday". Speaking of which, have you smelled this tiny ad?
the value of filler advertising in 2020
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic