Contact Us
  
 
 
    SearchSearch   RegisterRegister   Log inLog in 

java.lang.NullPointerException in jsp servlet and java

java.lang.NullPointerException in jsp servlet and java

 
Post new topic   Reply to topic     Forum Index -> Java,Struts framework, Velocity, JSF, Hibernate, Servlet, JSP, javaBeans
View previous topic :: View next topic  
Author Message
ronald



Joined: 11 Jun 2007
Posts: 2

PostPosted: Mon Jun 11, 2007 2:53 pm    Post subject: java.lang.NullPointerException in jsp servlet and java Reply with quote




I have always problem of null pointer in jsp and servlet. and sometime it take s too long to sort out this problem. java.lang.NullPointerException throws errors in client page. I do it very care fully. but still sometimes it throws
this exception of null pointer
java.lang.NullPointerException in the jsp page. any solution???????????
Back to top
View user's profile Send private message
markupsign



Joined: 06 Dec 2009
Posts: 0

PostPosted: Fri Jun 29, 2007 1:56 pm    Post subject: java.lang.NullPointerException in jsp servlet Reply with quote

it is very irritating about java.lang.NullPointerException error. when you are in learning stage, nullpointer creates lot of problem in our life. i also face that problem. and java is very strick about nullpointer. So always careful about this nullpointer exception while writing code.
Always do 2 precautions.
Quote:
1. Check condition string is null or not.
e.g if(string!=null)
2. if you are doing type casting your string to any other form
check always string. Is it go not null
e.g if(string!=null)
{
Integer.parseInt(string);
}
4. Always check request.getParameter("fieldName") with
if(request.getParameter("fieldName") !=null) mostly it comes null and create lot of problem
3. Easy technique. convert null to blank string by using method
in javabean or in jsp form and always use this in every string request.getParameter.
e.g
public String nullconv(String str)
{
if(str==null)
str="";
else if(str.equals("null"))
str="";
else if((str.trim()).equals(""))
str="";
else if(str.equals(null))
str="";
else
str=str.trim();

return str;
}
make method in reUseable.java

and use in your jsp

<jsp:useBean id="reUse" scope="page" class="com.special.ReUsableMethods" />
<%
String sGroupID=reUse.nullconv(request.getParameter("iGroupId"));
%>

if you want to use in only jsp page then
<%!
public String nullconv(String str)
{
if(str==null)
str="";
else if(str.equals("null"))
str="";
else if((str.trim()).equals(""))
str="";
else if(str.equals(null))
str="";
else
str=str.trim();

return str;
}
%>
<%
String sGroupID=reUse.nullconv(request.getParameter("iGroupId"));
%>


rest on you
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic     Forum Index -> Java,Struts framework, Velocity, JSF, Hibernate, Servlet, JSP, javaBeans All times are GMT
Page 1 of 1

 
Jump to:  
  Quick Post a Reply Topic
     
  Name (required)  
     
  Email Address (will not be published) (required)  
     
  Subject of topic (required)  
     
   
     
   
     
  Advertisement  
     
 
     


  More Links  
 
JSP Introduction
JSP Setup
Simple JSP Example
JSP Variable
Array Declaration in JSP
JSP Forms and User Input
Form Validation
JSP Cookies
JSP Session Object
Loop, content collection, iterator, conditional check in JSP
JSP Application Object
JSP Include
JSP Response Object
JSP Request Object
JSP Error Handling
JSP File Handling Object
JSP Action Tag
JSP Implicit Objects
JSP Declaration
JSP Directive
JDBC Introduction
JDBC Driver
JDBC Connection
JDBC Prepared/Statement
JDBC ResultSet
JDBC Close Connection object
JDBC Insert
JDBC Display Records
JDBC Update
JDBC Delete
JDBC Sorting
JDBC Query
JDBC Exception
JDBC Add Batch
JDBC Transaction/RollBack