This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Java Servlet

 
Muhammad Rehan Sheikh
Greenhorn
Posts: 1
  • 0
  • 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: 1510
  • 0
  • 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 )) {
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic