Share on Google+Share on Google+

nagarjuna
servelets
1 Answer(s)      7 years ago
Posted in : Java Beginners
I want to develop a small web application using netbeans.It contains a user login page,after sign into the page it will shows a new panel.


Plese send me links which contains theory and practical information.

Ads

View Answers

February 9, 2010 at 1:29 PM


Hi Friend,

Try the following code:

1)login.jsp:

<html>
<head>
</head>
<body>
<form name="form" method="post" action="../Authenticate">
<br><br>
<table align="center"><tr><td><h2>Login Authentication</h2></td></tr></table>
<table width="300px" align="center" style="border:1px solid #000000;background-color:#efefef;">
<tr><td colspan=2></td></tr>
<tr><td colspan=2>&nbsp;</td></tr>
<tr>
<td><b>Login Name</b></td>
<td><input type="text" name="username" value=""></td>
</tr>
<tr>
<td><b>Password</b></td>
<td><input type="password" name="password" value=""></td>
</tr>

<tr>
<td></td>
<td><input type="submit" name="Submit" value="Submit"></td>
</tr>
<tr><td colspan=2>&nbsp;</td></tr>
</table>
</form>
</body>
</html>

2)Authenticate.java:

import java.io.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class Authenticate extends HttpServlet {
public void doPost(HttpServletRequest request, HttpServletResponse response)throws IOException, ServletException{
PrintWriter out = response.getWriter();
String user=request.getParameter("username");
String pass=request.getParameter("password");
String user1="";
String pass1="";
HttpSession session = request.getSession(true);
try{
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","root";);
Statement st=con.createStatement();
ResultSet rs=st.executeQuery("select * from login where username='"+user+"' and password='"+pass+"'");
while(rs.next()){
user1 = rs.getString("username");
pass1 = rs.getString("password");
session.setAttribute("username",user1);
}
if((user1.equals(user))&&(pass1.equals(pass))){
response.sendRedirect("jsp/welcome.jsp");
}
else{
response.sendRedirect("jsp/login.jsp");
}
}
catch(Exception e){}
}
}

3)
<%
String user = session.getAttribute("username").toString();
%>
Welcome <%out.println(user);%>
<br>
<br>
<a href="#">Add</a><br>
<a href="#">Edit</a><br>
<a href="#">Delete</a>

Thanks









Related Tutorials/Questions & Answers:
Advertisements
web interface
web interface  hii sir, i want to develop a project name web GU interface for oracle like 10g can anyone help me plz how to develop using jsp and servelets provide code for WOI
reain values
reain values  Sir I have Jsp page for regisering customers,when i submit form it goes to servlet in servelets it checks for the username if it already exits i m using reuest.sendredirect to same jsp but all textbox values
Servlet Tutorials for Beginners
for a developer to learn Servlets to create dynamic web applications as Servelets
Tutorials   
Java Spring Hibernate Struts Training What does core Java include? java What are some way to learn Java quickly? Is it required to learn Java before learning Java Script? Is it necessary to learn java script before learning PHP? Are HTML5 and Java Script boosts Java career? Is Java object oriented? Fingerprint application with Java Uninstall Oracle Virtual Box JSON to HashMap Free Java online Training I want example of Control Statement in Java ANSI Color Codes with Python Create a Program that Calculates Input What is difference between JDK,JRE and JVM? How to see ubuntu version on server? How to get Page Source in Selenium (WebDriver) using Java? The path to the driver executable must be set by the webdriver.gecko.driver system property parse data from a link in java Java Program Qns using BlueJ How to fix HAX Kernel Module Is Not Installed error? Installing Audacity Looking for code Logic to check track changes & Coments in MSWord, MSWordx, MSExcel, MSExcelx is ON/OFF Installing JDK on Mac SAX Parser exception ERROR 601 (42P00): Syntax error. Encountered Thread java.lang.NoClassDefFoundError: org/apache/commons/fileupload/FileItemFactory How to install Ubuntu 16.04 LTS? HttpServletRequest cannot be resolved to a type in eclipse - Solved Unhandled event loop exception GC overhead limit exceeded Spring Data jpa with apache phoenix Caused by: java.lang.IllegalArgumentException: Not a host:port pair: PBUF o.a.h.h.z.RecoverableZooKeeper - Possibly transient ZooKeeper, quorum= com.thinkaurelius.titan.diskstorage.hbase.HBaseStoreManager class not found com.thinkaurelius.titan.diskstorage.hbase.HBaseStoreManager not found How to download and install Java 8 on Windows? How to uninstall JDK 7? How to install gtk-doc-tools package in Ubuntu? How to install Oracle JDK 8 on Ubuntu? ejabberd_ctl.beam not found - Solved How to convert date to UTC format in Java? How to install autoconf, automake and libtool in Ubuntu 15.10? How to convert current date to mm dd yyyy format in Java? How to convert current date to dd mm yyyy format in Java? How to stop window closing in "internalFrameClosing" event. How to find list of all index in Neo4j? neo4j-server.properties file location SASLError using PLAIN: not-authorized how to convert war file into .exe file using java code

Ads

 
Advertisement null

Ads