Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Servlet Exception

 
Sandhya Deekonda
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
toukhir mujawar
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can you please type in the code for your servlet and the html file?

that can make the picture clear...
 
Sandhya Deekonda
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
toukhir mujawar
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...
 
Sandhya Deekonda
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Still i'm getting the same error.
 
Sandhya Deekonda
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Sandhya Deekonda
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried still i'm getting tht error only wat may be the reason???
Thanks,
Sandhya.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Muhammad Saifuddin
Ranch Hand
Posts: 1325
Android Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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..
 
Sandhya Deekonda
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ya i recompiled with that switch still i get tht error.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Sandhya Deekonda
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
 
yu wang
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65535
108
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!