This week's book giveaway is in the Cloud/Virtualizaton forum.
We're giving away four copies of Mesos in Action and have Roger Ignazio on-line!
See this thread for details.
Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

I am not getting forwarded to another page where i want to go

 
Rushi Patel
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello all,
I am preparing an Online TestModule...
in which i am dealing with

CreateTest.jsp
CreateTestServlet.java (controller)
CreateTestModel.java (model)

Destination Page::
----------------------
CreateTestForm.jsp

Error I am getting is::
--------------------------

Oct 02, 2011 11:57:24 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet CreateTestServlet threw exception
java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.String

at org.apache.jsp.CreateTestForm_jsp._jspService(CreateTestForm_jsp.java:58)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:377)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:646)
at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:436)
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:374)
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:302)
at controller.CreateTestServlet.processRequest(CreateTestServlet.java:58)
at controller.CreateTestServlet.doPost(CreateTestServlet.java:89)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
at org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:859)
at org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:579)
at org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1555)
at java.lang.Thread.run(Thread.java:722)


all files code are as follows:
==================

CreateTest.jsp
-----------------------------


CreateTestServlet.java
------------------------------------


CreateTestModel.java
----------------------------------
 
Gopakumar Naryanan
Ranch Hand
Posts: 72
Eclipse IDE Hibernate Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rushi Patel wrote:hello all,
Oct 02, 2011 11:57:24 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet CreateTestServlet threw exception
java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.String

at org.apache.jsp.CreateTestForm_jsp._jspService(CreateTestForm_jsp.java:58)
[/color]


This means in your CreateTestForm.jsp , you are trying to cast an Integer to String.

Please provide the code for your CreateTestForm.jsp
 
Rushi Patel
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
gopakumar kiing wrote:


it had problm in some of jsp scriplets....
now i have used Static variable of "qno"
instead of using context parameter...!

now its completely working...!
 
Rushi Patel
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Information in Red was not supported , so i have put it into comment and now its working for me but i am trying to get reason for that why it didnot supported...!
 
Gopakumar Naryanan
Ranch Hand
Posts: 72
Eclipse IDE Hibernate Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ,

There is no possibility that the highlighted code causing the specified Exception.
You might have changed the code.
In the Exception Message it showed that you were trying to cast an Integer type to String.
(this is nowhere found in your highlighted code)

 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64858
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You shouldn't have any Java code in your JSP to begin with. That is a poor practice that has been discredited for 10 years now!

In any case, use red is a poor way topmost code. Red on tan is barely readable.

Rather, please be sure to use code tags when posting code to the forums. Unformatted or unindented code is extremely hard to read and many people that might be able to help you will just move along to posts that are easier to read. Please click this link ⇒ UseCodeTags ⇐ for more information. Properly indented and formatted code greatly increases the probability that your question will get quicker, better answers.
 
Rushi Patel
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
gopakumar kiing wrote:Hi ,

In this jsp code,....
when i remove this commented part ...its absolutely work very well...
but its not working with that portion uncommented.,...!

you got my point ??



 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64858
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
From looking at the trace, it seems as if the exception is occurring in a file that has not even bee shown to us.
 
Paul Clapham
Sheriff
Posts: 21107
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
On the other hand, the posted code clearly shows a cast to the String type. If you were to guess that the exception referred to that line of code, then that would mean that the expression being cast was actually of the Integer type.

And then somebody familiar with the application in question should be able to determine what is setting that servlet context attribute and fix the problem accordingly.
 
Gopakumar Naryanan
Ranch Hand
Posts: 72
Eclipse IDE Hibernate Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Rushi,

Still my reply remains the same.
You might have changed the code.. Nowhere you are trying to convert an Integer to String.
 
Ravi Khadgi
Greenhorn
Posts: 20
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
getServletContext().getAttribute("tnum") should be of type "Integer".
(String)getServletContext().getAttribute("tnum") tries to convert an "Integer" to "String" type.

I recommend you to use toString() method if you want the String.
Use Integer.intValue() function if you want the primitive int.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64858
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ravi Khadgi wrote:I recommend you to use toString() method if you want the String.

That could cause a null pointer exception if the scoped variable does not exist. Best to use String.valueOf() if there is a need for String conversion (which I am not convinced of) .
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic