Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa JSP-Servlet Log out from website
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


Parveen
Log out from website
1 Answer(s)      6 years and 7 months ago
Posted in : JSP-Servlet


what is the code to how to log out from the website?


Advertisement
View Answers

March 17, 2008 at 9:23 PM


Java Example code of Login and Logout from the applications...

LoginPage.jsp

<html>
<head>
<title>login page in jsp</title>
</head>
<body>
<table border="1" width="30%" cellpadding="0" cellspacing="0">
<tr>
<td width="100%">
<form method="POST" action="loginAction.jsp">
<h2>Login Page In JSP</h2>
<table border="1" width="100%" cellpadding="0" cellspacing="0">
<tr>
<td width="50%"><b>Username:</b></td>
<td width="50%"><input type="text" name="username" size="25"></td>
</tr>
<tr>
<td width="50%"><b>Password:</b></td>
<td width="50%"><input type="password" name="password" size="25"></td>
</tr>
</table>
<p><input type="submit" value="Submit" name="B1">
<input type="reset" value="Reset" name="B2"></p>
</form>
</td>
</tr>
</table>

</body>

</html>

loginAction.jsp


<%@ page language="java" import="java.sql.*,java.util.*,java.text.*" %>

<%

Connection con = null;
String url = "jdbc:mysql://localhost:3306/";;
String db = "register";
String driver = "com.mysql.jdbc.Driver";
java.util.Date date;
String s=null;
try{
Class.forName(driver);
con = DriverManager.getConnection(url+db,"root","root");
try{
Statement st = con.createStatement();
String username=request.getParameter("username");
String password=request.getParameter("password");

int val = st.executeUpdate("insert userlogin values('"+username+"','"+password+"')");

session.setAttribute("username", request.getParameter("username"));%>
Welcome to <%= session.getAttribute( "username" ) %>

<% if (session.getAttribute("username").equals("") && session.getAttribute("password").equals("")){%>
<a href="loginPage.jsp"><b>Login </b></a>
<%}
else{%>
<a href="logoutAction.jsp"><b>Logout</b></a>
<%}%>
<%
con.close();
}
catch (SQLException ex){
System.out.println("SQL statement is not executed!");
}
}
catch (Exception e){
e.printStackTrace();
}

%>

- - - - -- -
logoutAction.jsp

<%@page import="java.util.*" %>

<%session.invalidate();%>
You have logout. Please try again
<a href="loginPage.jsp"><b>Login</b></a>
----------

Using the above given code you can write a application the will allow a user to log in and log out from the application using JSP

JSP Tutorials
http://www.roseindia.net/jsp




Related Tutorials/Questions & Answers:
Log out from website - JSP-Servlet
Log out from website  what is the code to how to log out from the website?  Java Example code of Login and Logout from the applications... a user to log in and log out from the application using JSPJSP Tutorialshttp
log out
log out  how do i create a log out on a project without it exiting system so it does not reload again
Advertisements
how can we prevent back option after log out.
how can we prevent back option after log out.  how can we prevent back option after log out
auto log out the application if its inactive for longer period
auto log out the application if its inactive for longer period  hi all, Please tell me how to auto log out the application if its not performing any activity for longer period in jsp i tried to use session.setMaxInactiveInterval
log in
log in  sir i designed one login.jsp page with one form, username,login,and one submit button .if i enter username and password its been verify the mydatabase in in table in the field of username and password while it s correct
Sending error code to access log of tomcat server from Action class
Sending error code to access log of tomcat server from Action class  How to send an error code (500) to access log file when we get null value in an if condition in Action class? Is anyone aware of this! Thanks
How to delete content of a log file from linux terminal?
How to delete content of a log file from linux terminal?  Hi, My... running queries. But first I want to delete the content of the /var/log/slow... of the mysql log file: cat /dev/null > /var/log/slow-queries.log Thanks
How to convert http website into Https from java?
How to convert http website into Https from java?  could any one tell me how to convert http website into Https from java
To download a website from a given url. - JSP-Servlet
To download a website from a given url.  write a program to download a website from a given URL.it must download all the pages from that website.it should take the depth of retrieval from user input.all the files pages must
How to read a log file from server location and send a mail when exception occurs.
How to read a log file from server location and send a mail when exception occurs.  HI, How can i read the 2GB to 4GB log file from server. and i need to send a mail when exception occurs. Thanks Rajeev
website
website  i have uploaded website .website is woking properly in chrome & firefox but not in IE
download xml file from website using java code
download xml file from website using java code  how to download xml file from website using java code
Log-in Valdidation
Log-in Valdidation  how to create login validation in jsp
website
website  design and coding of first page of any forum website in jsp
website
website  How to paste data directly on any website' text box
how to scrape the data from one website another website using html dom parsing in php
how to scrape the data from one website another website using html dom parsing in php  " how to scrape the data from one website another website using html dom parsing in php" i'm trying this one .please provide code for me
How to Get The Data from Excel sheet into out jsp page???
How to Get The Data from Excel sheet into out jsp page???  How to Get The Data from excel sheet to out jsp page in webApp
Take print out from printer at client machienusing jsp - JSP-Servlet
Take print out from printer at client machienusing jsp  Sir/Mam I want do is to take out print out of my report which will be created from the Mysql database with out displaying him/her the results or report from the printer
how to write to java program to get the particular data from the website
how to write to java program to get the particular data from the website   i have to get the particular data by selecting the just numbers.. from the site .. how to get the ful details from the website by clicking the number
log 4j
log 4j  what is log4j? can you give me clear information about log4j?   Please go through the following link: log4j Tutorials
how to send sms from my website to mobile of particular user.
how to send sms from my website to mobile of particular user.  i had created a website and aim of pjt is whoever the client register for site with their mobile number daily one health tip is to sent to their respective mobiles
error log
error log  hi my requirement is validate xml and xsd in java.If there is an errors then i will log error and store into error table. so plz if any one knows send code urgent. error table details-------------- Table
how to get data from list to map with out using a loop?
how to get data from list to map with out using a loop?  List list=new ArrayList(); list.add("raja"); list.add("1"); list.add("puja...("15"); how to get this data into map with out using a loop. i want
log in page
log in page  hi all i want to create a login page in jsp which should be validated using ajax. please help me dong that with code...   Here is a jsp example that accepts username and password from the user and check
failure to log in
failure to log in  <blockquote> <p>Blockquote</p> </blockquote> <p>&lt;%@page contentType="text/html"%>... from customer_details where user_name=? and password
Writing Log Records to a Log File
Writing Log Records to a Log File       This section demonstrates for writing log records to a log file. Logger provides different types of level like: warning, info
Fetching data from excel file on other website and display in interactive graph form
Fetching data from excel file on other website and display in interactive graph form  Hello, I am making a website using HTML and CSS, I am done... pull data data from those and generate graphs out of it? I really need it urgently
to update drop down list value when selected from website
to update drop down list value when selected from website  hi help me, i want to insert value into db when i select from a drop down list...=mysql_query("select * from age order by Age_Desc"); while($row_list=mysql_fetch
to update drop down list value when selected from website
to update drop down list value when selected from website  hi help me, i want to insert value into db when i select from a drop down list...=mysql_query("select * from age order by Age_Desc"); while($row_list=mysql_fetch
to update drop down list value when selected from website
to update drop down list value when selected from website  hi help me, i want to insert value into db when i select from a drop down list...=mysql_query("select * from age order by Age_Desc"); while($row_list=mysql_fetch
user log in according to their role
user log in according to their role  i want a jsp code for different users log in to different pages according to their role.example normal user and administrator. normal user for user page and administrator for admin page
 

 

 

DMCA.com