Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Servlets
Search Coderanch
Advance search
Google search
Register / Login
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
Jeanne Boyarsky
Ron McLeod
Paul Clapham
Liutauras Vilda
Sheriffs:
paul wheaton
Rob Spoor
Devaka Cooray
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Carey Brown
Frits Walraven
Tim Moores
Bartenders:
Mikalai Zaikin
Forum:
Servlets
Requested Dispatcher
Ram Kas
Ranch Hand
Posts: 83
posted 17 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Can anybody provide me with good example on how to use RequestDispatcher?
Thanks in advance.
Dinakar.K
Bear Bibeault
Sheriff
Posts: 67746
173
I like...
posted 17 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
What did you not understand after reading the API description?
[
Asking smart questions
] [
About Bear
] [
Books by Bear
]
Ram Kas
Ranch Hand
Posts: 83
posted 17 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
The following is my code. I am not sure if it is right or wrong but I don't see HelloWorldExample page.
IndexServlet
import javax.servlet.*; import javax.servlet.http.*; import java.io.*; public class IndexServlet extends HttpServlet{ public void doGet(HttpServletRequest req, HttpServletResponse res)throws ServletException, IOException{ PrintWriter out = res.getWriter(); out.println("<HTML>"); out.println("<BODY>"); out.println("<form action = 'LoginServlet' method = 'GET' >"); out.println("<input type = 'text' name = 'username'>"); out.println("<input type = 'text' name = 'password'>"); out.println("<input type = 'submit' value = 'submit'>"); out.println("</form>"); out.println("</BODY>"); out.println("</HTML>"); } }
LoginServlet
import javax.servlet.*; import javax.servlet.http.*; import java.io.*; public class LoginServlet extends HttpServlet { public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { PrintWriter out = res.getWriter(); String username = req.getParameter("username"); String password = req.getParameter("password"); if(username!= null && password != null && username.equals("james") && password.equals("007")) { out.println("Logged in successfully"); [B]RequestDispatcher rd = req.getRequestDispatcher("/servlet/HelloWorldExaxmple"); rd.forward(req,res);[/B] } else{ out.println("Login Failed"); } } }
Bear Bibeault
Sheriff
Posts: 67746
173
I like...
posted 17 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Does the
servlet
work when you type the URL in by hand?
[
Asking smart questions
] [
About Bear
] [
Books by Bear
]
Ram Kas
Ranch Hand
Posts: 83
posted 17 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Yep
Bear Bibeault
Sheriff
Posts: 67746
173
I like...
posted 17 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Pulling teeth: have you verified that it is indeed executing the if-branch that contains the invocation of the dispatcher?
[
Asking smart questions
] [
About Bear
] [
Books by Bear
]
Bear Bibeault
Sheriff
Posts: 67746
173
I like...
posted 17 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
OK, so it turns out you have been completely wasting my time because you cross-posted the question in another topic.
Closing this topic.
[ August 02, 2006: Message edited by: Bear Bibeault ]
[
Asking smart questions
] [
About Bear
] [
Books by Bear
]
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
Exception Handling
Novell eDirectory
BPM Tool
Number of Days, Hours and Minutes
reading an xml file
More...