Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Spring Framework | Web Services | BioInformatics | Java Server Faces | Jboss 3.0 tutorial | Hibernate 3.0 | XML

Tutorial Categories: Ajax | Articles | JSP | Bioinformatics | Database | Free Books | Hibernate | J2EE | J2ME | Java | JavaScript | JDBC | JMS | Linux | MS Technology | PHP | RMI | Web-Services | Servlets | Struts | UML

Fresher Job


 

Search Host

Monthly Fee($)
Disk Space (MB)
Register With us for Newsletter!
Visit Forum! Post Questions!
Jobs At RoseIndia.net!

Have tutorials?
Add your tutorial to our Java Resource and get tons of hits.

We offer free hosting for your tutorials. and exposure for thousands of readers. drop a mail
roseindia_net@yahoo.com
 
   

Tutorials

Java Server Pages

JAXB

Java Beans

JDBC

MySQL

Java Servlets

Struts

Bioinformatics

Java Code Examples

Interview Questions

 
Join For Newsletter

Powered by groups.yahoo.com
Visit Group! Post Questions!

Web Promotion

Web Submission

Submit Sites

Manual Submission?

Web Promotion Guide

Hosting Companies

Web Hosting Guide

Web Hosting

Linux

Beginner Guide to Linux Server

Frameworks

Persistence Framework

Web Frameworks

Free EAI Tools

Web Servers

Aspect Oriented Programming

Free Proxy Servers

Softwares

Adware & Spyware Remover

Open Source Softwares

Null pointer exception error in Jsp
Expert:Majid
Expert:Majid
Hi i write a login page. when i validate the login value then the nullpointer exception error is occured.

my login page code is

<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>
<!-- This is the Login page to the system -->
<html>
<head>
<title>Login Page</title>
<link rel="stylesheet" href="header.css" media="all" type="text/css">
<style type="text/css" media="screen">
table
{
border: 1px solid #036;
}
th
{ color: #036;
background: lightblue;
font-size: 120%;
border-bottom: 1px solid #036;
}
td
{
padding: .5em;
}
</style>

<script LANGUAGE="JavaScript" type="text/javascript">
function validate_fields()
{
var uid=document.getElementById("userid").value;
var upwd=document.getElementById("pwd").value;

if(uid=="")
{
alert("user name should not empty");
return false;
}
else if(upwd=="")
{
alert("Password should not be empty");
return false;
}
else
{
return true;
}
}
</script>

</head>
<body>
<h1 id="header">Web-Based Bug Tracking System</h1>
<br><br>

<p align="center">Please enter your id and password to login.</p>

<form id="login" name="login" method="post" action="validateLogin.jsp" onSubmit="return validate_fields()" >

<table align="center">
<th colspan="2">Login</th>
<tr>
<td>User id:</td><td><input type="text" id="userid" size="20"></td></tr>
<tr>
<td>Password:</td><td><input type="password" id="pwd" size="21"></td></tr>
<tr>
<td></td><td><input type="submit" value="Login"></td></tr>
</table>
</form>

</body>
</html>


and the validatelogin page code is

<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>
<%@ page import="java.sql.*" %>
<%@ page import="java.util.*" %>
<html>
<head><title>validateLogin Page</title>
<%

%>

</head>
<body>
<%
try
{

String id=request.getParameter("userid");
String userpwd=request.getParameter("pwd");
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String str = "select * from Member";
Connection conn = DriverManager.getConnection("jdbc:odbc:bugsdb.mdb");
Statement stt = conn.createStatement();
ResultSet res = stt.executeQuery(str);
String str1;
String str2;

while(res.next())
{
str1=res.getString("User_Id");
str2=res.getString("User_Pwd");
if(id.equals(str1) && userpwd.equals(str2) )
{
response.sendRedirect("userpage.jsp");
}
else
{
response.sendRedirect("Login.jsp");
}
}
}catch (ClassNotFoundException cnfe)
{
cnfe.printStackTrace();
}
%>
</body>
</html>


when i run this code then the following error is occured.

HTTP Status 500 -

--------------------------------------------------------------------------------

type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

org.apache.jasper.JasperException
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:358)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:301)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:248)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:305)


root cause

java.lang.NullPointerException
org.apache.jsp.validateLogin_jsp._jspService(validateLogin_jsp.java:76)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:133)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:311)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:301)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:248)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:305)


note The full stack trace of the root cause is available in the Tomcat logs.


--------------------------------------------------------------------------------

Apache Tomcat/5.0.19


note i used netbean ide 3.6. Pleas help me how i finished this error. i need quick response.
Answers
Hi friend,


Error in your Code and check it :

<input type="text" id="userid" size="20">
<input type="password" id="pwd" size="21">


validatelogin page

String id=request.getParameter("userid");
String userpwd=request.getParameter("pwd");


You have not "name" attributes in the input tag
So id,userpwd gives null pointer exception.

Thanks

dear friends i used the name attribute but it still have error of runtimeNULL execption.

Please povide me a solution to this code or an alternative solution.
thanks.

Answers
Hi friend,

Error in this lines of Code because you not having attributes "name" in the
input tag.

<tr>
<td>User id:</td><td><input type="text" id="userid" size="20"></td></tr>
<tr>
<td>Password:</td><td><input type="password" id="pwd" size="21"></td></tr>
<tr>

Correct code :

<tr>
<td>User id:</td><td><input type="text" id="userid" name="userid" size="20"></td></tr>
<tr>
<td>Password:</td><td><input type="password" id="pwd" name="pwd" size="21"></td></tr>
<tr>

Thanks

More Questions
Post Answers
 
Ask Question Facing Programming Problem?
Useful Links
  JDO Tutorials
  EAI Articles
  Struts Tutorials
  Java Tutorials
  Java Certification

Tell A Friend
Your Friend Name
Search Tutorials

 

 
 
Browse all Java Tutorials
Java JSP Struts Servlets Hibernate XML
Ajax JDBC EJB MySQL JavaScript JSF
Maven2 Tutorial JEE5 Tutorial Java Threading Tutorial Photoshop Tutorials Linux Technology
Technology Revolutions Eclipse Spring Tutorial Bioinformatics Tutorials Tools SQL
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2007. All rights reserved.