This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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 Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Java Servlet" Watch "Java Servlet" New topic

Java Servlet

Muhammad Rehan Sheikh

Joined: Mar 23, 2002
Posts: 1
this code send null pointer exception any one pls correct this and mail me.
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 )) {
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: 1510
First check userid and password for null before calling the equals method.
if(userid != null) && (password != null)
if(userid.equals (u.userid ) && password.equals (u.password )) {

So much trouble in the world -- Bob Marley
I agree. Here's the link:
subject: Java Servlet
Similar Threads
Servlet User Roles
null pointer exception
package does not exist
kindly help me in redirecting....... as soon as possible
comparing strings with equals method