HI,
Follow the procedure
1.Create a jsp page name like login.jsp(remember in login.jsp in action you will put the servlet name like action="login.java")
2.Then create a servlet page name like login.java
3.Then create another java class Login.java(It the same name of the sevlet)where get and set mathod will be used.
4.Then create another java class where you will put your database connectivity logic.
Go through the code and create the files USING netbeans ide or eclipse then
enjoy :)))))))))))
here is the code for jsp page like login.jsp(omit the css thingd just pick up the html code and make page by yourself)
<%@ page contentType="text/html; charset=utf-8" language="java" import="java.sql.*" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "
http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">;
<html xmlns="
http://www.w3.org/1999/xhtml"; xml:lang="fr"><head><title>Secure Networks Technologies - Web Server</title>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<link rel="stylesheet" href="cryptonet_files/config.css" type="text/css">
<style type="text/css">
.style1 {
color: red;
}
</style><script charset="utf-8" id="injection_graph_func" src="cryptonet_files/injection_graph_func.js"></script></head><body>
<div id="container">
<div id="banner"> <img src="cryptonet_files/bluetooth.jpg" alt="" border="1" height="100" width="798">
<img src="cryptonet_files/Safe%2520Server.jpg" alt="" border="1" height="100" width="798">
</div>
<div id="outer">
<div id="inner">
<div id="left" style="">
<br>
<strong>
</strong><pre><a href="index.jsp"><img src="images/home.png" border="0" width="32" height="32" > </a><span class="style1"><a href="index.jsp"> <font color = red> Home </font> </a></span>
</pre>
<p>
<br>
<br>
</p>
</div>
<div id="content" style="">
<h1> Login</h1>
<p class="MsoNormal">
<span lang="EN-US">
<br>
</span>
</p><p><span lang="EN-US"></span></p>
<span lang="EN-US"><table border="0" cellpadding="0" cellspacing="0">
<!-- CryptoNet Section ----------------------------------------------------- -->
<tbody><tr> <td colspan="2"> <table width="476" border="0">
<tr>
<td width="186">User Name </td>
<td width="274">
<form name="form2" id="form2" method="post" action="login.java">
<input type="text" name="textfield" />
</form></td>
</tr>
<tr>
<td>Password</td>
<td><input type="text" name="textfield2" /></td>
</tr>
<tr>
<td> </td>
<td> <span lang="EN-US"><span lang="EN-US"><span lang="EN-US"><span lang="EN-US">
<input type="submit" name="Submit" value="Login" />
</span></span></span></span></td>
</tr>
</table> <strong> </strong></td></tr>
<!-- blank line -->
<!-- blank line -->
<!-- BotNet Section ----------------------------------------------------- -->
<!-- blank line -->
<!-- blank line -->
<!-- WirelessNet Section ----------------------------------------------------- -->
<!-- blank line -->
<tr> <td width="60"> </td>
<td align="west" valign="top" width="500">
<form name="form1" id="form1" method="post" action="">
<span lang="EN-US"><span lang="EN-US"><span lang="EN-US"><span lang="EN-US">
</span></span></span></span> <span lang="EN-US"><span lang="EN-US">
</span></span>
</form></td>
</tr>
</tbody></table>
<span lang="EN-US"></span><br>
<br>
</span>
<p> </p>
</div>
<!-- end content -->
</div>
<!-- end inner -->
</div><!-- end outer -->
<div id="footer"> Last updated on May 02, 2008</div>
</div><!-- end container -->
</body>
</html>
login.java servlet code is given below:
package com.servlet;
import java.io.IOException;
import com.model.idms.Login;
import com.model.idms.actions.IDMSDelegate;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
/**
*
* @author hasan
*/
public class login extends HttpServlet {
public login(){
super();
}
/**
* Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
* @param request servlet request
* @param response servlet response
*/
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
String username=request.getParameter("username");
String password=request.getParameter("password");
//Create the instance of the Login class
Login login=new Login();
login.setusername(username);
login.setpassword(password);
//create the instance of the IDMS Delegate
IDMSDelegate idmsdelegate=new IDMSDelegate();
idmsdelegate.addlogin(login);
HttpSession session=request.getSession(true);
session.setAttribute("loginobject",login);
getServletConfig().getServletContext().getRequestDispatcher("/submit_app.jsp").forward(request,response);
}
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}
/**
* Handles the HTTP <code>POST</code> method.
* @param request servlet request
* @param response servlet response
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}
/**
* Returns a short description of the servlet.
*/
}
This is the code of Login.java where the set and get method is given below:
package com.model.idms;
/**
*
* @author hasan
*/
public class Login {
private String firstname;
private String lastname;
private String email;
private String username;
private String password;
private String contract_type;
//private String identification_type;
private String creditcard;
private String co;
private String zipcode;
private String identification;
private String number;
private String contract;
private String street;
private String country;
private String language;
private String amount;
private String interval;
private String address;
private String city;
private String cellphone;
private String homephone;
private String currency;
private String payment;
private String frequency;
public void sethomephone(String homephone){
this.homephone=homephone;
}
public String gethomephone(){
return homephone;
}
public void setfrequency(String frequency){
this.frequency=frequency;
}
public String getfrequency(){
return frequency;
}
public void setcountry(String country){
this.country=country;
}
public String getcountry(){
return country;
}
public void setlanguage(String language){
this.language=language;
}
public String getlanguage(){
return language;
}
public void setinterval(String interval){
this.interval=interval;
}
public String getinterval(){
return interval;
}
public void setcity(String city){
this.city=city;
}
public String getcity(){
return city;
}
public void setamount(String amount){
this.amount=amount;
}
public String getamount(){
return amount;
}
public void setpayment(String payment){
this.payment=payment;
}
public String getpayment(){
return payment;
}
public void setaddress(String address){
this.address=address;
}
public String getaddress(){
return address;
}
public void setcurrency(String currency){
this.currency=currency;
}
public String getcurrency(){
return currency;
}
public void setcellphone(String cellphone){
this.cellphone=cellphone;
}
public String getcellphone(){
return cellphone;
}
public void setstreet(String street){
this.street=street;
}
public String getstreet(){
return street;
}
public void setco(String co){
this.co=co;
}
public String getco(){
return co;
}
public void setzipcode(String zipcode){
this.zipcode=zipcode;
}
public String getzipcode(){
return zipcode;
}
public void setidentification(String identification){
this.identification=identification;
}
public String getidentification(){
return identification;
}
public void setnumber(String number){
this.number=number;
}
public String getnumber(){
return number;
}
public void setcontract(String contract){
this.contract=contract;
}
public String getcontract(){
return contract;
}
public void setcreditcard(String creditcard){
this.creditcard=creditcard;
}
public String getcreditcard(){
return creditcard;
}
public void setcontract_type(String contract_type){
this.contract_type=contract_type;
}
/*public void setidentification_type(String identification_type){
this.getidentification_type=identification_type;
}
*/
public void setfirstname(String firstname){
this.firstname=firstname;
}
public String getfirstname(){
return firstname;
}
public void setlastname(String lastname){
this.lastname=lastname;
}
public String getlastname(){
return lastname;
}
public void setemail(String email){
this.email=email;
}
public String getemail(){
return email;
}
public void setusername(String username) {
this.username=username;
}
public String getusername(){
return username;
}
public void setpassword(String password){
this.password=password;
}
public String getpassword(){
return password;
}
}
here is the IDMSDelegate.java
package com.model.idms.actions;
import com.model.idms.Login;
import com.utility.DBHandlerIdms;
import java.sql.ResultSet;
/**
*
* @author hasan
*/
public class IDMSDelegate {
private DBHandlerIdms db = new DBHandlerIdms();
private ResultSet rs = null;
public boolean addlogin(Login login){
try{
db.makeconnection();
//String query= "insert into login(username,password) values('"+Login.getusername()+"','"+Login.getpassword()+"')";
String query = "insert into login (username,password) values ('"+login.getusername()+"','"+login.getpassword()+"' )";
int a=db.executeUpdate(query);
if(a>0){
db.releaseConnection();
return true;
}
else{
db.releaseConnection();
return false;
}
}catch(Exception ex){
ex.printStackTrace();
return false;
}
}
}
And here is the IDMDHandler.java
package com.utility;
import java.sql.*;
/**
*
* @author hasan
*/
public class DBHandlerIdms {
public Connection connection;
public Statement stmt;
public ResultSet rs;
public String user="root";
public String pass="admin";
public String url="jdbc:
mysql://localhost:3306/idms";;
public String driver="com.mysql.jdbc.Driver";
//public String url="jdbc:
mysql://localhost:3306/idms";;
//public String driver="com.mysql.jdbc.Driver";
public DBHandlerIdms(){
}
public Connection makeconnection()throws Exception{
Class.forName(driver);
connection=DriverManager.getConnection(url,user,pass);
return connection;
}
public void releaseConnection()throws Exception{
connection.close();
}
public ResultSet executeQuery(String query)throws Exception{
rs=null;
stmt=connection.createStatement();
rs=stmt.executeQuery(query);
return rs;
}
public int executeUpdate(String query)throws Exception{
int rowaffected=0;
stmt=connection.createStatement();
rowaffected=stmt.executeUpdate(query);
return rowaffected;
}
}