permaculture playing cards*
The moose likes Servlets and the fly likes Passing Control from JSP to Servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Passing Control from JSP to Servlet" Watch "Passing Control from JSP to Servlet" New topic
Author

Passing Control from JSP to Servlet

Venny Ra
Greenhorn

Joined: Nov 10, 2011
Posts: 5
Hi All,

I am working on this project and facing some issues. Am a newbie in web development and need your assitance.

Here is my problem: I created a JSP page with a form and input fields. Once the form is submitted, I want the data to be processed by servlet which further invokes a DAO class that interacts with database and generates the response based on what user entered. Little diagram will probably explain it well.

login.jsp ---------> loginServlet --------> loginDAO (check if the username is already in DB) ------------> success.jsp (if username exists) error (otherwise).

I am putting the location for login servlet in form action attribute but it cant find it. I have tried all means.

I can put the code here if you need for reference. Eagerly waiting for the reply.

Thanks
Venny
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61092
    
  66

Usually a RequestDispatcher is used to forward the request from a servlet to a JSP.

You might want to read through this article.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Venny Ra
Greenhorn

Joined: Nov 10, 2011
Posts: 5
Bear Bibeault wrote:Usually a RequestDispatcher is used to forward the request from a servlet to a JSP.

You might want to read through this article.


Hi, thanks for the reply. I am able to pass the control from servlet to jsp but my problem is coming to servlet from jsp. like say I have a form with values taken from user, how do I pass the control to servlet to process the form ?


Thanks
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61092
    
  66

The action attribute of the form should address the servlet.
 
jQuery in Action, 2nd edition
 
subject: Passing Control from JSP to Servlet