Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Im doing a website using jsp,servlet and java. I have two buttons (login and logout) in the same Jsp page(Login.jsp).it's methods (loginSession and logoutSession) are in same servlet file(GetServlet.java) also. my question is how to connect login button to loginSesssion and logout button to logoutSession?
Posted

Here is my code

Java
<![CDATA[<%@page import="com.mobitel.bankdemo.web.GetSession"%>]]>
<![CDATA[<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>]]>
 
Share this answer
 
Comments
mali_angel 7-Jul-13 9:55am    
thank u :)
Java
<![CDATA[<%@page import="com.mobitel.bankdemo.web.GetSession"%>]]>
<![CDATA[<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>]]>
 
Share this answer
 
There are so many way to handle this.

Process 1
=============
1. Create a hidden filed in your jsp called as "ReqType" .
2.Set value as per Login/Logout request.
2. Read this value in servlet
Java
String type request.getParameter("ReqType")
if("LOGOUT".equals(type)){
//do logout operation
}else if("LOGIN".equals(type)){
//do login operation
}


Process 2
=============
1. Assume that requested url are
http://localhost:8080/login
http://localhost:8080/logout
2. add both url pattern in you web.xml file to point the same servlet

3.And read the Uri info in servlet

Java
String uri = request.getRequestURI();
if("/login".equals(uri)){
//do login operation
}else if("/logout".equals(uri)){
//do logout operation
}
 
Share this answer
 
Comments
mali_angel 5-Jul-13 7:27am    
Do i have to do both operations? or only one?
Shubhashish_Mandal 5-Jul-13 7:29am    
No, you have to implement any one of them.
mali_angel 7-Jul-13 0:42am    
I have an another issue..in my project Login.jsp page login button connects to UserServlet.java file.but I took another file to keep session codes. I want to connect Login.jsp to Usersevlet.java file loginDetail method. Inside that method I need to Call Session file loginSession method. my question is how to do that?
Shubhashish_Mandal 7-Jul-13 5:07am    
If you have any issue then please start with other thread.
Thanks

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900