It's not a secret anymore!*
The moose likes Servlets and the fly likes Java Servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Java Servlet" Watch "Java Servlet" New topic
Author

Java Servlet

Muhammad Rehan Sheikh
Greenhorn

Joined: Mar 23, 2002
Posts: 1
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");
}
}


Hello I need some help of about java servlet.
Bosun Bello
Ranch Hand

Joined: Nov 06, 2000
Posts: 1506
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 )) {


Bosun (SCJP, SCWCD)
So much trouble in the world -- Bob Marley
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Java Servlet
 
Similar Threads
Servlet User Roles
comparing strings with equals method
null pointer exception
package does not exist
kindly help me in redirecting....... as soon as possible