recently I wrote a basic web application with only index.jsp and a simple servlet, here’s the code:
index.jsp
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<h1>Hello W!</h1>
<form action="Hello.do">
<p>Wprowadź imię: </p>
<input type="text" name="imie"/>
<input type="submit" value="OK"/>
</form>
</body>
in web.xml there is a fragment linking Hello.do to servlet HelloServlet.java:
<web-app>
<display-name>Archetype Created Web Application</display-name>
<servlet>
<servlet-name>HelloServlet</servlet-name>
<servlet-class>pl.helion.jeeweb.HelloServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>HelloServlet</servlet-name>
<url-pattern>/Hello.do</url-pattern>
</servlet-mapping>
</web-app>
and of course servlet in package pl.helion.jeeweb.
But when I launch the application, fill the form and click OK, I get:
javax.servlet.ServletException: Error instantiating servlet class pl.helion.jeeweb.HelloServlet
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:929)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:405)
...
root cause
java.lang.ClassNotFoundException: pl.helion.jeeweb.HelloServlet
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1678)
...
so what’s wrong?
and by the way, sorry for my english and thanks for help;]
My problem was that I had a bad folder structure. By default package and servlet were in folder resources, all I had to do was to rename it to java