Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: Java JSP Servlet
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 5-Jul-13 1:46am
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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
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
 
String uri = request.getRequestURI();
if("/login".equals(uri)){
//do login operation
}else if("/logout".equals(uri)){
//do logout operation
}
  Permalink  
Comments
mali_angel at 5-Jul-13 7:27am
   
Do i have to do both operations? or only one?
Shubhashish_Mandal at 5-Jul-13 7:29am
   
No, you have to implement any one of them.
mali_angel at 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 at 7-Jul-13 5:07am
   
If you have any issue then please start with other thread.
Thanks
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

<![CDATA[<%@page import="com.mobitel.bankdemo.web.GetSession"%>]]>
<![CDATA[<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>]]>
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 5

Here is my code
 
<![CDATA[<%@page import="com.mobitel.bankdemo.web.GetSession"%>]]>
<![CDATA[<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>]]>
  Permalink  
Comments
mali_angel at 7-Jul-13 9:55am
   
thank u :)

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

  Print Answers RSS
0 Kornfeld Eliyahu Peter 169
1 George Jonsson 145
2 Zoltán Zörgő 139
3 PIEBALDconsult 130
4 OriginalGriff 120
0 OriginalGriff 6,165
1 DamithSL 4,658
2 Maciej Los 4,107
3 Kornfeld Eliyahu Peter 3,649
4 Sergey Alexandrovich Kryukov 3,382


Advertise | Privacy | Mobile
Web04 | 2.8.141220.1 | Last Updated 7 Jul 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100