how to handle request.getParameter(String) methods for NullPointerExceptoin for the request.
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Yousuf_Badar
Posted On:   Thursday, September 12, 2002 02:33 AM

how to handle request.getParameter(String) methods for NullPointerExceptoin for the request. i have the request.getParameter("txt") method to get the values of a parameter "txt". which is posted from the same page. but when the page is loaded for the first time it does not get any request from anywhere so it gives a NullPointerExceptoin. how do i handle the request/response? the exception is not being handled !!!! <% String inputdate=""; inputdate=request.getParameter("txt"); %> Date : <%=inputdate%>>        More>>


how to handle request.getParameter(String) methods for NullPointerExceptoin for the request.


i have the request.getParameter("txt") method to get the values of a parameter "txt". which is posted from the same page. but when the page is loaded for the first time it does not get any request from anywhere so it gives a NullPointerExceptoin. how do i handle the request/response? the exception is not being handled !!!!



			
<%
String inputdate="";
inputdate=request.getParameter("txt");
%>





Date :
<%=inputdate%>>
   












   <<Less

Re: how to handle request.getParameter(String) methods for NullPointerExceptoin for the request.

Posted By:   AlessandroA_Garbagnati  
Posted On:   Thursday, September 12, 2002 02:37 AM

Hi,

You should check if the parameter is null, and if it is null, just assign an empty string. You have to do that after reading the parameter, for example.

String inputdate = request.getParameter("txt");
if (inputdate == null) {
inputdate = ""; // or any default you like
}

This is the easiest solution.
About | Sitemap | Contact