Total members 11895 |It is currently Tue Dec 03, 2024 7:18 pm Login / Join Codemiles

Java

C/C++

PHP

C#

HTML

CSS

ASP

Javascript

JQuery

AJAX

XSD

Python

Matlab

R Scripts

Weka





i m trying to develop a login page and following is the coding of the login servlet but when i try to run this it throws a NullPointerException .i dont know why but this statement ServletContext sc= getServletContext(); is throwing this exception can anyone tell me the reason for this.
thanking u in anticipation
java code
import java.io.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class LoginEx extends HttpServlet{
Connection conn;

public void init(ServletConfig s) throws ServletException
{
try
{

System.out.println("hello1");
ServletContext sc=getServletContext();
System.out.println("hello1");
String st=sc.getInitParameter("dbclass");

Class.forName(st);
conn = DriverManager.getConnection(sc.getInitParameter("dbconn"),sc.getInitParameter("dbuser"),sc.getInitParameter("dbpass"));

}
catch(Exception cn)
{
System.out.println("error"+cn);throw new ServletException();
}
}
protected void doPost(HttpServletRequest req,HttpServletResponse resp)throws ServletException,IOException
{

resp.setContentType("text/html");
PrintWriter pw = resp.getWriter();
String n=req.getParameter("name");
String p=req.getParameter("pass");
try{

Statement st=conn.createStatement();
ResultSet rs= st.executeQuery("select * from login where ename="+n+"and pass="+p);
while(rs.next())
{
pw.println("<html><body>welcome</body></html>");
}
}
catch(Exception e){
System.out.println("error"+e);
}
pw.close();

}



}





Author:
Newbie
User avatar Posts: 1
Have thanks: 0 time
Post new topic Reply to topic  [ 1 post ] 

  Related Posts  to : develop a login page- login servlet - ServletContext
 Login page using sessions and mysql in php     -  
 track session from login page-J2EE project     -  
 login using jsp     -  
 Ajax Login     -  
 ASP.NET 2.0 Login Controls     -  
 php login with session     -  
 login using Ajax     -  
 How to Show a message before the login ?     -  
 Send login information     -  
 Login using session with php and mysql     -  









Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com