This week's book giveaway is in the OCAJP 8 forum.
We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line!
See this thread for details.
The moose likes Servlets and the fly likes HTTP Status 500 - Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "HTTP Status 500 - " Watch "HTTP Status 500 - " New topic

HTTP Status 500 -

sunil khandelwal

Joined: Aug 02, 2010
Posts: 5

I am new to servlet.

when i run servlet then it gives this error.

HTTP Status 500 -

type Exception report


description The server encountered an internal error () that prevented it from fulfilling this request.


javax.servlet.ServletException: Class GetData is not a Servlet

root cause

java.lang.ClassCastException: GetData

note The full stack trace of the root cause is available in the Apache Tomcat/5.5.30 logs.
Apache Tomcat/5.5.30

and my code is:-

import javax.servlet.*;
import javax.servlet.http.*;

import java.sql.*;

import java .io.*;

public class GetData extends HttpServlet
private static final long serialVersionUID = 1L;

public void doPost(HttpServletRequest request,HttpServletResponse response) throws IOException,ServletException
response.setContentType("text/html" );
PrintWriter out = response.getWriter();
String names[] = new String[5];
names[0] = request.getParameter("aa1");
names[1] = request.getParameter("aa2");
names[2] = request.getParameter("aa3");
names[3] = request.getParameter("aa4");
names[4] = request.getParameter("aa5");

/*try {
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
} catch (SQLException e) {
// TODO Auto-generated catch block
RequestDispatcher dp = request.getRequestDispatcher("../../sunil.jsp");

/*private void Database_connection(HttpServletRequest request) throws ClassNotFoundException, SQLException {
String db = "jdbcdbc:name";
Connection connection = DriverManager.getConnection(db);
String s = "INSERT INTO name_table (no , tittle) VALUES (?,?)";
PreparedStatement preparedstatement = connection.prepareStatement(s);
String no = request.getParameter("aa1");
String tittle = request.getParameter("aa2");
preparedstatement.setString(1, no);
preparedstatement.setString(2, tittle);


please give me the solution of this problem.

Thanks in advance.
SbhargavS Surimenu

Joined: Mar 09, 2010
Posts: 4
With my knowledge Every class that extends GenericSerlvet or HttpServlet should be treated as a servelt by the server.
I have reviewed your servelt, but I didnt see any problems with your servlet. Have you configured your servelt in web.xml ?

Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63349

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.

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
sunil khandelwal

Joined: Aug 02, 2010
Posts: 5

Yes i configured web.xml file.

yup next time i will be taking care of code tags.
David Newton

Joined: Sep 29, 2008
Posts: 12617

sunil khandelwal wrote:Yes i configured web.xml file.

We can't see it, though.

Please edit your post to include code tags.

Also, servlets must not be in the default package.
Mathew Lee
Ranch Hand

Joined: Jun 08, 2009
Posts: 238
Please post web.xml.
sunil khandelwal

Joined: Aug 02, 2010
Posts: 5
thanks to all of u.

I got the solution.

This problem was coming because of wrong tomcat structure.
I agree. Here's the link:
subject: HTTP Status 500 -
It's not a secret anymore!