problem in jsp

i have created a one jsp in which i imported a package such as follow

<%@page import="tourpack.*"%>

<%@page import="java.sql.*"%>

<html>

<script language="javascript">

function showdt()

{

dt=new Date()

m=dt.getMonth()+1

d=dt.getDate()+"/"+m+"/"+dt.getYear()

document.frm.tdt.value=d

}

</script>

<style>

td

{

font-family:verdana;

color:brown;

font-size:13;

}

</style>

<%

//out.print(request.getParameter("pno"));

int pno=Integer.parseInt(request.getParameter("pno"));

Tourpackge pk=new Tourpackge(pno);

String pknm=pk.findName();

//int bgt=pk.findbgt();

//int dur=pk.finddur();

//int hld=pk.findhld();

String detail=pk.finddetail();

Connection con=null;

Statement st=null;

ResultSet rs=null;

try

{

String userName = "root";

String password = "root";

String url = "jdbc:mysql://localhost:3306/admin";

Class.forName ("com.mysql.jdbc.Driver");

con = DriverManager.getConnection (url, userName, password);

st=con.createStatement();

}

catch(Exception ex){System.out.println(ex);}

%>

<body bgcolor="seashell" onload="showdt()">

<center>

<h2>Package updation</h2>

<form name="frm" method="post" action="/emanpower/jsp/updateFinal.jsp">

<table width="400" cellspacing="7">

<tr>

<td>Updation Date

<td><input type="text" name="tdt">

</tr>

<tr>

<td>Package ID

<td><input type="text" name="pno" value="<%=pno%>" readonly >

</tr><tr>

<td>Package Name

<td><input type="text" name="enm"value="<%=pknm%>" readonly>

</tr><tr>

<td>Current Package Detail

<td><input type="text" name="ct" value="<%=detail%>" readonly>

</tr><tr bgcolor="pink">

<td>New Package Detail

<td><input type="text" value="newdetail">

<%

rs.close();

st.close();

con.close();

%>

<td colspan="2"><center><input type="submit" value="Udate">

</tr>

</table>

</form>

<a href="/contact/jsp/admin.jsp">Admin Home</a>

</body>

</html>

but when i run this jsp it shows error

such as

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

exception

org.apache.jasper.JasperException: Exception in JSP: /updatepack.jsp:23

20:</style>

21:<%

22://out.print(request.getParameter("pno"));

23:int pno=Integer.parseInt(request.getParameter("pno"));

24:Tourpackge pk=new Tourpackge(pno);

25:String pknm=pk.findName();

26://int bgt=pk.findbgt();

Stacktrace:

org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:504)

org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:393)

org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)

org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)

javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:368)

root cause

java.lang.NumberFormatException: null

java.lang.Integer.parseInt(Integer.java:415)

java.lang.Integer.parseInt(Integer.java:497)

org.apache.jsp.updatepack_jsp._jspService(updatepack_jsp.java:67)

org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)

javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:332)

org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)

org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)

javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:368)

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

can any body solve my problem

thanks

shrinath

[4532 byte] By [shrinathbherdea] at [2007-11-27 6:02:11]
# 1

It looks like the request parameter "pno" doesn't exist so that

request.getParameter("pno")

returns null which can not be parsed into an

int value which causes

int pno=Integer.parseInt(request.getParameter("pno"));

to throw an exception

You may want to put a check before the parse

int pno = 0;

if (request.getParameter("pno") != null)

pno=Integer.parseInt(request.getParameter("pno"));

tolmanka at 2007-7-12 16:43:14 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2
or:int pno = (request.getParameter("pno") != null ? Integer.parseInt(request.getParameter("pno")) : 0);if you are not a big fan of if statements.
gimbal2a at 2007-7-12 16:43:14 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3

Or:

int pno = getParamAsInt(request, "pno");

public static int getParamAsInt(HttpServletRequest request, String param) {

return request.getParameter(param) != null ? Integer.parseInt(request.getParameter(param)) : 0;

}

If you're a big fan of reuseable utility methods. You may add a try-catch on NFE which prevents new NFE's if the value is not 100% numeric.

BalusCa at 2007-7-12 16:43:14 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...