Win a copy of Rust Web Development this week in the Other Languages forum!

john_smith

Greenhorn
+ Follow
since May 10, 2002
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by john_smith

to is the my first day that i am joining this forum. i hope i will get the good responce .
my email importdoc@hotmail.com
In the servlet below i am trying to compare tow string .
one i am retrieving from the database and othe i am decalaring in the instane variable in the doPost method
on the baese of these two string i wan to navigate between different pages.
i am using weblogic and sql server.

package projServlets;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.http.HttpServlet;
import java.util.*;
import java.io.*;
import java.sql.*;
public class LoginServlet extends HttpServlet{

public void doPost(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
Connection con = null;
Statement statement = null;
ResultSet rs = null;
Object enu_obj = null;
String userid= null;
String password = null;
String category = null;
String category1 = "manager"; //the value of string i want to compare
res.setContentType("text/html");
PrintWriter out= res.getWriter();
String userid1 = req.getParameter("userid");
String password1 = req.getParameter("password");
try{
String strsql ="SELECT userid,password,category " +
"FROM customer WHERE userid = '"+userid1+"'";
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con =DriverManager.getConnection("jdbc dbc roject");
statement = con.createStatement();
rs = statement.executeQuery(strsql);
Vector vec_get_user = new Vector();
while(rs.next()){
try{
vec_get_user.addElement(rs.getString("userid"));
vec_get_user.addElement(rs.getString("password"));
vec_get_user.addElement(rs.getString("category"));
}catch(Exception e){
e.printStackTrace();
}
}
Enumeration enum = vec_get_user.elements();
while(enum.hasMoreElements()){
enu_obj = enum.nextElement();
if (enu_obj!=null){
userid = (String)enu_obj;
}
enu_obj = enum.nextElement();
if (enu_obj!=null){
password = (String)enu_obj;
}
enu_obj = enum.nextElement();
if (enu_obj!=null){
category = (String)enu_obj;
}
}
if (userid==null || password==null){
res.sendRedirect("http://localhost:7001/projecthtml/logindenied.html");
}
//the values of two string to be compared
//category is coming from the database
//category1 is defined in the instance variable
if (category.equals(category1)) {
res.sendRedirect("http://localhost:7001/projecthtml/manager.html");
}
else
res.sendRedirect("http://localhost:7001/projecthtml/user.html");
}catch (SQLException sql){
System.err.println(sql.getMessage());
}catch (ClassNotFoundException cnf){
System.err.println(cnf.getMessage());
}catch (Exception e){
System.err.println(e.getMessage());
}

}

}
19 years ago