You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Jim McNamara <jm...@proton.me.INVALID> on 2023/07/04 23:36:11 UTC
plaint text version of question: hello world w3schools (tomcat)
Hi-
I am resending my msg. in plain text wondering how to get tomcat to render my servlet for hellworld from code I got at w3schools.
I am trying to follow the guidelines:
TOMCAT 10.1.10 + plain text email!
THANKS
code and configuration files:
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.Servlet;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
/**
* This servlet program is used to print "Hello World" on
* client browser by implementing servlet interface.
* @author w3spoint
*/
public class HelloWorld implements Servlet {
private static final long serialVersionUID = 1L;
//no-argument constructor.
public HelloWorld() {
}
ServletConfig config=null;
@Override
public void init(ServletConfig config) throws ServletException {
this.config = config;
System.out.println("Do initialization here.");
}
@Override
public void destroy() {
System.out.println("Do clean-up process here.");
}
@Override
public ServletConfig getServletConfig() {
return config;
}
@Override
public String getServletInfo() {
return "w3spoint.com";
}
@Override
public void service(ServletRequest request, ServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<h1>Hello World example using " +
"servlet interface.</h1>");
out.close();
}
}
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<servlet>
<servlet-name>HelloWorld</servlet-name>
<servlet-class>
HelloWorld
</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>HelloWorld</servlet-name>
<url-pattern>/HelloWorld</url-pattern>
</servlet-mapping>
</web-app>
url:
http://localhost:8080/examples/HelloWorld
<Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="false">
<context docbase="webapps" path="/webapps/examples"/>
error msg:
Root Cause
java.lang.ClassCastException: class HelloWorld cannot be cast to class jakarta.servlet.Servlet
Sent with Proton Mail secure email.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org