• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

exception while running code

 
Ranch Hand
Posts: 225
IBM DB2 Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
through the following code i am extracting values from database for edit purpose and the following code is calling when i am click on the edit button that is along with every row of table of jsp page



but it is giving following error


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



i don't understand why this error is coming

 
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

java.lang.NumberFormatException: For input string: "UserServlet"


Is "UserServlet" a number?
 
Megha Singhal
Ranch Hand
Posts: 225
IBM DB2 Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Maneesh Godbole wrote:

java.lang.NumberFormatException: For input string: "UserServlet"


Is "UserServlet" a number?



no its a class name
 
Maneesh Godbole
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok. What I meant was do you now figure out what is going wrong?
 
Megha Singhal
Ranch Hand
Posts: 225
IBM DB2 Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Maneesh Godbole wrote:Ok. What I meant was do you now figure out what is going wrong?



no.. not yet
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
the following line causes this exception

Integer.parseInt(str[3]);

try printing str[3]
i guess it's something thats not an integer
 
Megha Singhal
Ranch Hand
Posts: 225
IBM DB2 Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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



i'm trying to edit particular record on the basis of P_ID and it is a integer type.
i provide that in the database
 
Maneesh Godbole
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Maybe.
But what you are getting from

String str[] = request.getRequestURI().toString().split("/");
int P_ID = Integer.parseInt(str[3]);


is not an integer.
 
Megha Singhal
Ranch Hand
Posts: 225
IBM DB2 Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.



so can you please tell me what changes i have to make so that it will not show this exception.
 
Maneesh Godbole
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Like you were told before, try printing what actual values you are getting.
 
Megha Singhal
Ranch Hand
Posts: 225
IBM DB2 Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Maneesh Godbole wrote:Like you were told before, try printing what actual values you are getting.



but actual values i'm getting in string through session from the previous page but i have to convert it into the integer as in database that is stored in the form of integer and query will work only when i match the field of integer type.
 
Maneesh Godbole
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Megha Singhal
Ranch Hand
Posts: 225
IBM DB2 Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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?



My first jsp page is following

and when i click on edit button then it should redirect me to follwing servlet


and after it should take me to following jsp page

on this page fetched value should be shown
 
Maneesh Godbole
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Maneesh Godbole wrote:
So do you want to share what it prints?


 
Ranch Hand
Posts: 68
IBM DB2 Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
what i think. In code:


str[3] is null. so check these by printing the value of str[3]. if it is null or not.
 
Ranch Hand
Posts: 672
4
Eclipse IDE Spring Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Megha Singhal
Ranch Hand
Posts: 225
IBM DB2 Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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?



now i change the code but stll it is not redirecting me to jsp

and my below code that is for delete that is working which is following and redirecting me to other page

 
Prasad Krishnegowda
Ranch Hand
Posts: 672
4
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am just wondering, is it so difficult to do what we all suggested here (just printing one value and posting here the result..)

I request for the last time. Please post the value of the variable been passed to Integer.parseInt() as suggested by Maneesh,Rsudha and Neeraj already.

If you just keep on posting code, without doing what's suggested, its of no use.
Also, posting things like, below code is working and below is not working, will not help. You are expecting us to keep on guessing what changes you did?
You need to TellTheDetails, such as what changes you did, what you expected and what came..

 
Sheriff
Posts: 9708
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If the value is coming as a query string, you can simply use request.getParameter to get its value...
 
Megha Singhal
Ranch Hand
Posts: 225
IBM DB2 Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ankit Garg wrote:If the value is coming as a query string, you can simply use request.getParameter to get its value...



when i am passing the the value below like this and disable to bring variable from the previous page then it is giving below output that is what i want



but i have to work generaly on that it is not working

i have attached the output screen shot that is based on fix value.

and following is syntax for calling from the previous page to this servlet page , the event which has to be performed on button click

function editRecord(P_ID){

window.location.href="../edit/UserServlet?"+P_ID;
}


New-Picture.png
[Thumbnail for New-Picture.png]
output screen shot
 
Bartender
Posts: 2270
20
Android Java ME Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are you sure that the following path is correct?

String nextJSP = "../jsp/editUser.jsp";
 
Megha Singhal
Ranch Hand
Posts: 225
IBM DB2 Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Swastik Dey wrote:Are you sure that the following path is correct?

String nextJSP = "../jsp/editUser.jsp";



as i told it is working on fix value but not on query string and the screen shot i attached that is coming because i have given the proper path.
that's for sure prob is not in the path there is something in the query string
 
Swastik Dey
Bartender
Posts: 2270
20
Android Java ME Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Does exception stack trace say something?
 
Ranch Hand
Posts: 196
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Why can't you use query parameter instead of query string.
You can try with following code changes.
JavaScript



Java Code




 
Megha Singhal
Ranch Hand
Posts: 225
IBM DB2 Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Swastik Dey wrote:Does exception stack trace say something?



No
 
Megha Singhal
Ranch Hand
Posts: 225
IBM DB2 Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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?
 
Piyush Mangal
Ranch Hand
Posts: 196
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You are already defining userId in your js function (see below). What we are doing here is P_ID will be passed as a request parameter with the name "userId" which we get by using request.getParameter("userId") in servlet.




 
Megha Singhal
Ranch Hand
Posts: 225
IBM DB2 Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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?



now this is giving following error


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
Ranch Hand
Posts: 196
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My Apologies for typo.

It should be String str = request.getParameter("userId");
 
Megha Singhal
Ranch Hand
Posts: 225
IBM DB2 Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Piyush Mangal wrote:My Apologies for typo.

It should be String str = request.getParameter("userId");



but the problem still same .
i'm still not able to redirect to jsp page actualy this servlet will run only when i connect it with previous jsp page as query string is passing from jsp to servlet page and then i am redirecting it to the next jsp page so the problem is still same i'm not able to redirect to next jsp page.
my main problem is this only that it is not going on next page and there is no error in the path as this path is working on another but i'm not understanding why it is not working on this page.
 
Piyush Mangal
Ranch Hand
Posts: 196
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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

 
Megha Singhal
Ranch Hand
Posts: 225
IBM DB2 Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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



i already mentioned those servlet and jsp above but i am mentioning again.

below is the first jsp page

below is the servlet on which the jsp page will redirect on edit button click

below is the jsp code on which servlet should redirect

so above are the required servlet and jsps







 
Neeraj Dhiman
Ranch Hand
Posts: 68
IBM DB2 Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Megha Singhal
Ranch Hand
Posts: 225
IBM DB2 Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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?



yes this is redirecting to my college main page.
it is in our server if there is any error in code then it will redirect to college main page without showing any exception or error
 
Neeraj Dhiman
Ranch Hand
Posts: 68
IBM DB2 Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
it mean there is errors in your code. have you checked your console for exception? your are using e.printStackTrace();
try to find in which segment of code you got exception which will caused to redirect to another page.
 
Swastik Dey
Bartender
Posts: 2270
20
Android Java ME Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In you jsp you have something like. What does this mean?
request.getAttribute("userList")!=""

You probably want to make sure that the list not empty?


Problem 2, you are initializing the arraylist inside the loop


So what happens in the above code, every time the loop executes a new arraylist object is created, means it will always store only the last record in the array list. Initialize it before you start the loop.
 
Piyush Mangal
Ranch Hand
Posts: 196
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Megha Singhal
Ranch Hand
Posts: 225
IBM DB2 Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.



in my jsp P_ID is defined so i have to use P_ID and i alraedy made changes in req.getparameter but still problem is coming
 
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
reply
    Bookmark Topic Watch Topic
  • New Topic