Forums Register Login

Servlet Exception

+Pie Number of slices to send: Send
Hi Everyone,
I've written a webapplication, which has one html file and one servlet.In the html file if i click a button then the servlet is called.there i'm getting an error like

javax.servlet.ServletException: Error allocating a servlet instance

rootcause:java.lang.UnsupportedClassVersionError: Bad version number in .class file

Why do i get such sort of error can anyone help me out???

Thanks,
Sandhya.
+Pie Number of slices to send: Send
can you please type in the code for your servlet and the html file?

that can make the picture clear...
+Pie Number of slices to send: Send
Servlet Code:

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;

public class SampleServlet extends HttpServlet
{
public void service(HttpServletRequest request,HttpServletResponse response)throws IOException
{
try
{
PrintWriter out=response.getWriter();
out.println ("Servlet called");
}
catch(Exception e)
{ e.printStackTrace();}
}
}

Html code:

<html>
<head> <title> ........</title> </head>
<body>
<form action="SampleServlet">
<input type="text" name="nameField" value="">
<input type="submit" value="Submit">
</form>
</body>
</html>
there is nothing much code simple servlet only.
+Pie Number of slices to send: Send
you try changing this code......

public void service(HttpServletRequest request,HttpServletResponse response)throws IOException

to........

public void service(HttpServletRequest request,HttpServletResponse response)throws IOException, ServletException

that should work...
+Pie Number of slices to send: Send
Still i'm getting the same error.
+Pie Number of slices to send: Send
I'm compiling servlet file using jdk1.6 and my server is installed with jdk1.5
is this the reason for getting tht error?? let me know if soo....
Thanks,
Sandhya.
+Pie Number of slices to send: Send
 

Originally posted by Sandhya Deekonda:
I'm compiling servlet file using jdk1.6 and my server is installed with jdk1.5
is this the reason for getting tht error?? let me know if soo....
Thanks,
Sandhya.



Yes, re-compile the class with the following switch:
-source 1.5
+Pie Number of slices to send: Send
I tried still i'm getting tht error only wat may be the reason???
Thanks,
Sandhya.
+Pie Number of slices to send: Send
Did you re-compile with the switch mentioned above?

If so, did you make sure to place the new class file where the old one was?
Did you restart the server so it will reload the class file?
+Pie Number of slices to send: Send
 

Originally posted by Ben Souther:


Yes, re-compile the class with the following switch:
-source 1.5



Why is it so ? is this issue about compatibility or is about difference in generated JDK 1.5 or JDK 6 class file.. If it is then what is the major difference between these class files.

Thanks in Advance..
+Pie Number of slices to send: Send
Ya i recompiled with that switch still i get tht error.
+Pie Number of slices to send: Send
 

Originally posted by Saif uddin:


Why is it so ? is this issue about compatibility or is about difference in generated JDK 1.5 or JDK 6 class file.. If it is then what is the major difference between these class files.

Thanks in Advance..



A JRE can't be expected to interpret a class file that was compiled with a future version of javac. The source switch is the compiler's way of telling the JRE that there are no features in this class file that aren't compatible with the JRE.
The compiler will enforce this by blowing up if you try to compile source code that has features that weren't present in the named version.
+Pie Number of slices to send: Send
 

Originally posted by Sandhya Deekonda:
Ya i recompiled with that switch still i get tht error.



Please take the time to answer all of the questions asked of you.
I asked you three questions.
You answered only one.

If you're new to web forums like JavaRanch, you would do well to take a minute and read our How To Ask Questions On JavaRanch page.
http://faq.javaranch.com/view?HowToAskQuestionsOnJavaRanch
+Pie Number of slices to send: Send
Sorry Ben i'm new 2 this forum.Atlast i got it. I uninstalled my jdk6.0 and installed jdk5.0 now its working.i was in the process of uninstalling and installing so i couldn't respond fastly.Thanks alot.
Thanks,
Sandhya.
+Pie Number of slices to send: Send
Glad it's working for you.
+Pie Number of slices to send: Send
It is a problem about your JDK version. Maybe the version of building the class and the version of running the class are not same.
+Pie Number of slices to send: Send
 

Originally posted by Sandhya Deekonda:
i'm new 2 this forum.



"2" is not a word. Being new to the forums please note that we prefer that you use real words when posting to the forums.
Stop it! You're embarassing me! And you are embarrassing this tiny ad!
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 1064 times.
Similar Threads
pls help me in javabean usage in jsp(doubt)
tomcat 4.1
How to run Servlets with Weblogic 6.1
getWriter() has already been called for this response
Help: Websphere- invoking error reporter
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 08:17:48.