| Author |
how to manage same servlet for different jsps
|
Kavitha hebbar
Greenhorn
Joined: Sep 12, 2012
Posts: 9
|
|
Hi,
I have a login page where user information is collected passed to the servlet where it is connected to DAO class where it validates the email received with the database.If emails are different it will provide new userid for that user sends it to register.jsp.Now the user enters the password and all the in formation should be stored in the database.How to connect to the servlet now? Is the same servlet we have to use( if so how and what method we have to use?)If different servlet how it is?I am using MVC architecture.
Please suggest me.
KH
|
 |
Chetan Dorle
Ranch Hand
Joined: Aug 06, 2009
Posts: 128
|
|
Hi Kavitha ,
You can use different Servlet or same servlet .
But as if you find some information about MVC it is said that Servlet should be made as controller and how it is made is by using only single servlet and giving wildcard mapping for servlet .
One of the topic may help you is http://www.coderanch.com/t/359118/Servlets/java/Wildcard-servlet-mappings-web-xml OR you can also search for the wildcard mapping for servlet .
- Chetan
Guys correct me if anything doesn't seems right.
|
 |
Kavitha hebbar
Greenhorn
Joined: Sep 12, 2012
Posts: 9
|
|
Chetan Dorle wrote:Hi Kavitha ,
You can use different Servlet or same servlet .
But as if you find some information about MVC it is said that Servlet should be made as controller and how it is made is by using only single servlet and giving wildcard mapping for servlet .
One of the topic may help you is http://www.coderanch.com/t/359118/Servlets/java/Wildcard-servlet-mappings-web-xml OR you can also search for the wildcard mapping for servlet .
- Chetan
Guys correct me if anything doesn't seems right.
Hi,
thanks for the reply.But i did not get how to retrieve the values from second jsp form in the same servlet.Also i got 405 error saying get method is not supported by the url when i gave /* in servlet mapping.
Thank u.
Kavitha Gh
|
 |
Chetan Dorle
Ranch Hand
Joined: Aug 06, 2009
Posts: 128
|
|
Hi Kavitha ,
Can you mention your complete Servlet mapping in web xml and <form> action you are calling from page ?
- Chetan
|
 |
Kavitha hebbar
Greenhorn
Joined: Sep 12, 2012
Posts: 9
|
|
Hi,
I'm attaching the file form.jsp where i get info initially and goes to servlet for validation.Then comes web.xml where i map.Now i send some uid to register.jsp.in this jsp, user is allowed to enter password and here i want this to go to same servlet and thereby the data is stored into database.Is it possible and correct?How can it be achieved?
Thank u.
Kavitha hebbar
form.jsp
After this using a servlet which overrides dopost method and there i retrieve values from form.jsp thru request.getparameter.I don't know how to pass from register.jsp to same servlet and how to retrieve values.
Please help me.
|
 |
Chetan Dorle
Ranch Hand
Joined: Aug 06, 2009
Posts: 128
|
|
Hi Kavitha,
You can give same name in the action which you have given in form.jsp .
The problem is how you will decide that how decide from where servlet is called , for this you can add one hidden field in the form having value "REGISTER_FORM" and you can then easily distinguish.
I have modified register JSP
register.jsp
In the servlet you can write like
if("REGISTER_FORM".equalIgnoreCase(request.getParameter("FORM_SUBMITTED")))
{
// Do that database insertion code
//block for register.jsp
}
else
{
//This is for form.jsp
}
- Chetan
|
 |
Kavitha hebbar
Greenhorn
Joined: Sep 12, 2012
Posts: 9
|
|
Thanks a lot.
Kavitha hebbar
|
 |
 |
|
|
subject: how to manage same servlet for different jsps
|
|
|