Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

org.apache.jasper.JasperException: java.lang.NullPointerException

 
king singh
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<% String u=request.getParameter("act");
RequestDispatcher disp=null;%>


<%if(u.equalsIgnoreCase("ADD USER")){%>
<jsp:useBean id="user" class="b.user_bean"></jsp:useBean>
<jsp:setProperty name="user" property="*"/>
<%-- <jsp:getProperty name="user" property="u_nm"/>--%>
<%userDAO add_u=new userDAO();%>
<%String msg=add_u.add_user(user);

if(msg.equalsIgnoreCase("user id already exist"))
{%>
i m here
<%request.setAttribute("msg1", "user id already exist");
disp=request.getRequestDispatcher("add_u.jsp");
disp.forward(request, response);}
else{%>
i m outside<% }}


else if(u.equalsIgnoreCase("DELETE USER")){
String id=request.getParameter("id");
userDAO del_u=new userDAO();
del_u.del_user(id);
}
else if(u.equalsIgnoreCase("MODIFY USER"))
{%>
<jsp:useBean id="mod" class="b.user_bean"></jsp:useBean>
<jsp:setProperty name="mod" property="*"/>
<jsp:getProperty name="mod" property="u_id"/>
<%userDAO mod_u=new userDAO();%>
<%mod_u.mod_user(mod);}

else{
%>
No option
<%
}
%>

changes done successfully


</body>
</html>

After running this file i am getting org.apache.jasper.JasperException: java.lang.NullPointerException
What is the problem here?

My DAO file is


package dao;
import b.user_bean;
import java.sql.*;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
*
* @author Administrator
*/
public class userDAO {
Connection con ;
//user_bean user=new user_bean();
public userDAO(){
try{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection("jdbc:odbc:user","","");

}
catch(Exception e)
{
e.printStackTrace();
}
}

public String add_user(user_bean user)
{
try {
PreparedStatement ps = con.prepareStatement("insert into USER_INFO values(?,?,?,?,?,?,?,?,?)");
//System.out.println(user.getU_id());
Statement ps1 = con.createStatement();
ResultSet rs=ps1.executeQuery("select * from USER_INFO where UID='"+user.getU_id()+" '");
System.out.println(rs.next());
if(rs.next())
{
return "user id already exist";
}
else
{
ps.setString(1,user.getU_id());
}

ps.setString(2,user.getU_pass());
ps.setString(3,user.getU_nm());
ps.setString(4,user.getU_des());
ps.setString(5,user.getU_st());
ps.setString(6,user.getU_email());
ps.setLong(7, user.getU_phno());
ps.setLong(8, user.getU_mob());
ps.setString(9,user.getU_add());
ps.executeUpdate();

} catch (SQLException ex) {

}
return "";

}


public boolean del_user(String id)
{System.out.println(id);
try {
System.out.println(id);
LoginDAO login=new LoginDAO();
Statement ps = con.createStatement();
ResultSet rs=ps.executeQuery("select USER_PW,USER_NAME from USER_INFO where UID='"+id+" '");
rs.next();
System.out.println("hello"+id);
if(login.validate(rs.getString(2),rs.getString(1) ))
{
Statement s1 = con.createStatement();
System.out.println("he"+rs.getString(2));
System.out.println( s1.executeUpdate("delete from USER_INFO where UID='"+id+"'"));

return true;
}

}
catch (SQLException ex) {
Logger.getLogger(userDAO.class.getName()).log(Level.SEVERE, null, ex);
}
return false;
}


public boolean mod_user(user_bean mod)
{
try {
PreparedStatement ps = con.prepareStatement("update USER_INFO set USER_NAME=?, USER_DESIG=?,USER_STATUS=?,EMAIL=?,PH_NO=?,MOB_NO=?,ADDRESS=? where UID=?");
System.out.println(" User id in dao : " +mod.getU_id());

//ps.setString(1,mod.getU_id());
//ps.setString(2,mod.getU_pass());
ps.setString(1,mod.getU_nm());
ps.setString(2,mod.getU_des());
ps.setString(3,mod.getU_st());
ps.setString(4,mod.getU_email());
ps.setLong(5, mod.getU_phno());
ps.setLong(6, mod.getU_mob());
ps.setString(7,mod.getU_add());
ps.setString(8,mod.getU_id());
ps.executeUpdate();
} catch (SQLException ex) {
ex.printStackTrace();
}
return false;

Pleae guide me
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64613
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch. "king singh", please check your private messages for an important administrative matter. Thanks.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64613
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please be sure to use code tags when posting code to the forums. Unformatted or unindented code is extremely hard to read and many people that might be able to help you will just move along to posts that are easier to read. Please click this link ⇒ UseCodeTags ⇐ for more information. Properly indented and formatted code greatly increases the probability that your question will get quicker, better answers.

Also, putting Java code in a JSP is a bad practice from over 10 years ago! Is this legacy code form then? If not, why is there Java code in your JSP? One of the things that Java in JSP makes hard is debugging just this type of problem.

And finally, show use the error, don't just tell us about it.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic