HTTP Status 500 -
--------------------------------------------------------------------------------
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
java.lang.NumberFormatException: For input string: "UserServlet"
java.lang.NumberFormatException.forInputString(Unknown Source)
java.lang.Integer.parseInt(Unknown Source)
java.lang.Integer.parseInt(Unknown Source)
UserServlet.doPost(UserServlet.java:24)
javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
org.apache.catalina.servlets.InvokerServlet.serveRequest(InvokerServlet.java:402)
org.apache.catalina.servlets.InvokerServlet.doPost(InvokerServlet.java:170)
javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
InfonetFilter.doFilter(InfonetFilter.java:43)
note The full stack trace of the root cause is available in the Apache Tomcat/6.0.18 logs.
--------------------------------------------------------------------------------
Apache Tomcat/6.0.18
java.lang.NumberFormatException: For input string: "UserServlet"
Maneesh Godbole wrote:
java.lang.NumberFormatException: For input string: "UserServlet"
Is "UserServlet" a number?
Maneesh Godbole wrote:Ok. What I meant was do you now figure out what is going wrong?
SCJP,SCWCD
Rsudha Ramasamy wrote:the following line causes this exception
Integer.parseInt(str[3]);
try printing str[3]
i guess it's something thats not an integer
String str[] = request.getRequestURI().toString().split("/");
int P_ID = Integer.parseInt(str[3]);
Maneesh Godbole wrote:Maybe.
But what you are getting from
String str[] = request.getRequestURI().toString().split("/");
int P_ID = Integer.parseInt(str[3]);
is not an integer.
Maneesh Godbole wrote:Like you were told before, try printing what actual values you are getting.
Maneesh Godbole wrote:It does not really matter what you wish to do with the value.
Point is the string to int logic is failing because the string cannot be converted to an int.
So do you want to share what it prints?
Maneesh Godbole wrote:
So do you want to share what it prints?
Correct Me if i am wrong
Prasad Krishnegowda wrote:The exception clearly tells, that it cannot convert the String value to an Integer. That means check what is been passed to Integer.parseInt, it is not an number.
As suggested earlier by Maneesh and Rsudha, why can't you just print that value and show us what it prints?
SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Ankit Garg wrote:If the value is coming as a query string, you can simply use request.getParameter to get its value...
function editRecord(P_ID){
window.location.href="../edit/UserServlet?"+P_ID;
}
Swastik
Swastik Dey wrote:Are you sure that the following path is correct?
String nextJSP = "../jsp/editUser.jsp";
Swastik
Swastik Dey wrote:Does exception stack trace say something?
Piyush Mangal wrote:Hi,
Why can't you use query parameter instead of query string.
You can try with following code changes.
JavaScript
Java Code
Megha Singhal wrote:
Piyush Mangal wrote:Hi,
Why can't you use query parameter instead of query string.
You can try with following code changes.
JavaScript
Java Code
ok then where should i declare userId?
UserServlet.java:27: cannot find symbol
symbol : method getRequestParameter(java.lang.String)
location: interface javax.servlet.http.HttpServletRequest
String str = request.getRequestParameter("userId");
^
Piyush Mangal wrote:My Apologies for typo.
It should be String str = request.getParameter("userId");
Piyush Mangal wrote:Can you describe the structure of your web application including jsp folder.
Please also share the source code for
1. JSP from where you are taking user to Servlet.
2. The servlet which will forward the request to Jsp
Correct Me if i am wrong
Neeraj Dhiman wrote:ok. so you are not redirecting to another page then what is the error message or in which error page you are redirecting or something else.
is there any exception?
Correct Me if i am wrong
Swastik
Piyush Mangal wrote:Hi,
Why are you using ?P_ID="+P_ID and not ?userId="+P_ID in your javascript?
If you want to use ?P_ID="+P_ID , then in your code also , you will need to change request parameter name accordingly.
Those cherries would go best on cherry cheesecake. Don't put those cherries on this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
|