Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Java Servlet

 
Muhammad Rehan Sheikh
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this code send null pointer exception any one pls correct this and mail me.
objava2@hotmail.com
import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class loginServlet extends HttpServlet {
public void doGet(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
boolean b = false;
String userid = req.getParameter ("UTX");
String password = req.getParameter ("PTX");
ServletContext sc = getServletContext();
Vector vec = (Vector)(sc.getAttribute ("user"));
for(int i=0; i<vec.size (); i++) {
Users u = (Users)(vec.get (i));
if(userid.equals (u.userid ) && password.equals (u.password )) {
b=true;
break;
}
else
b=false;
}
if(b==true)
res.sendRedirect("/examples/welcomepg.htm");
else if(b==false)
res.sendRedirect ("/examples/REGFORM.htm");
}
}
 
Bosun Bello
Ranch Hand
Posts: 1511
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First check userid and password for null before calling the equals method.
if(userid != null) && (password != null)
then....
if(userid.equals (u.userid ) && password.equals (u.password )) {
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic