• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

servlets

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In a servlet how to send a data which is obtained in one servlet to another one servlet?
for example:
Iam writing a servlet to input an username and in this servlet iam checking whether the length is > than zero and i donno how to pass that name to another servlet where it is checked and then dispaly some message or something
 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,
use request dispatcher to the desired servlet
catch the request do the processing
RequestDispatcher rd =null;
rd=getServletContext().getRequestDispatcher("/");
hope this will use for u
 
kiruthika raghunathan
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
String username = request.getParameter("username");
if ( username != null && username.length() > 0 ) {
RequestDispatcher dispatcher =
getServletContext().getRequestDispatcher("/response");
if (dispatcher != null)
dispatcher.include(request, response);
I have done this in the first servlet i have to pass the name to another servlet and check it there
donno how to get it in that servlet?
 
Sheriff
Posts: 7001
6
Eclipse IDE Python C++ Debian Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It may be a silly question, but why does the code which checks the username need to be a servlet? Would it not make more sense just to use a regular java class, and simply call a method, passing in the username as a parameter?
 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
try this
getServletContext().getRequestDispatcher("/response").forward(HttpServletRequest,HttpServletResponse);
 
Ranch Hand
Posts: 645
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Adding more to Franks post,cant it be done thru javascript?
Removing HttpR,HttpR from to Nirants post,
getServletContext().getRequestDispatcher("/response").forward(request,response);
cheers
Praful
[ December 08, 2003: Message edited by: Praful Thakare ]
 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How about storing the username to a session variable, then retrieving that session variable in the second servlet.
 
"I know this defies the law of gravity... but I never studied law." -B. Bunny Defiant tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic