hi everybody,
I'm Developing a maintenence application where i'l have to Add new user information and new Department information.
The HTML page consist of Few TextBoxes and Command buttons.
Acutally i i donno how to validate which command button has created an event, based on which i can execute the query either
for adding New User or New Department..
As i donno how to validate which component has created the event..i've written two
servlet one for adding User and One for
adding Department, and have deployed it indivitually just for the sake to
test whether the data are inserted..
I want to make it as a single servlet..Can anyone help me with the code pls...
I've attached the html code and The two servlet codes
pls help me!
The Html page consiste on Two text box and a Comand Button on one from for inserting Username and password into the database and
another form comsist of two textbox and a command button for adding new DeptName and Dept Description
SERVLET 1 ----For Inserting NEW USER INFORMATION
------------------------------------------------
import javax.servlet.*;
import javax.servlet.http.*;
import javax.sql.*;
import java.io.*;
import java.sql.*;
public class LoginSAPOnlineMaintenence extends HttpServlet
{
static Connection dbcon;
public void doPost(HttpServletRequest req, HttpServletResponse res)throws ServletException,IOException
{
try
{
Class.forName("oracle.jdbc.driver.OracleDriver");
dbcon=DriverManager.getConnection("jdbc

racle:thin:@bbsu-2:1521:keonline","system","knowledge");
System.out.println("Connection Established");
}
catch(ClassNotFoundException e)
{
System.out.println("Database Driver not Found");
System.out.println(e.toString());
}
catch(Exception e)
{
System.out.println(e.toString());
}
res.setContentType("text/html");
PrintWriter out=res.getWriter();
String username=req.getParameter("username");
String password=req.getParameter("password");
String previledge=req.getParameter("previledge");
int rows=0;
try
{
PreparedStatement s=dbcon.prepareStatement("insert into login_info(username,password,previledge) values(?,?,?)");
s.setString(1,username);
s.setString(2,password);
s.setString(3,previledge);
rows=s.executeUpdate();
}
catch(Exception e)
{
System.out.println(e.toString());
}
if(rows==0)
{
System.out.println("Error Inserting Data into the Login Table");
}
else
{
System.out.println("The values have been inserted into the table successfully");
}
try
{
dbcon.close();
}
catch(Exception e)
{
System.out.println(e.toString());
}
}
}
SERVLET 2 FOR ADDING NEW DEPT INFORMATION
import javax.servlet.*;
import javax.servlet.http.*;
import javax.sql.*;
import java.io.*;
import java.sql.*;
public class DepartmentSAPOnlineMaintenence extends HttpServlet
{
static Connection dbcon;
public void doPost(HttpServletRequest req, HttpServletResponse res)throws ServletException,IOException
{
try
{
Class.forName("oracle.jdbc.driver.OracleDriver");
dbcon=DriverManager.getConnection("jdbc

racle:thin:@bbsu-2:1521:keonline","system","knowledge");
System.out.println("Connection Established");
}
catch(ClassNotFoundException e)
{
System.out.println("Database Driver not Found");
System.out.println(e.toString());
}
catch(Exception e)
{
System.out.println(e.toString());
}
res.setContentType("text/html");
PrintWriter out=res.getWriter();
String deptid=req.getParameter("deptid");
String deptname=req.getParameter("deptname");
int rows=0;
try
{
PreparedStatement s=dbcon.prepareStatement("insert into dept_info(D_ID,D_DESC) values(?,?)");
s.setString(1,deptid);
s.setString(2,deptname);
rows=s.executeUpdate();
}
catch(Exception e)
{
System.out.println(e.toString());
}
if(rows==0)
{
System.out.println("Error Inserting Data into the Login Table");
}
else
{
System.out.println("The values have been inserted into the table successfully");
}
try
{
dbcon.close();
}
catch(Exception e)
{
System.out.println(e.toString());
}
}
}