• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Java Servlet

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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");
}
}
 
Ranch Hand
Posts: 1514
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 )) {
reply
    Bookmark Topic Watch Topic
  • New Topic