java, javafx, android and spring programing collection
java standard edition
addObject
arraylist
bufferedreader
colors
comparator
createTable
datatypes
date
enum
generateHTML
hashmap
inheritance
insertSQL
interface
JSONfromWEB
jsoup
list
loop
pointMatrix
queue
readCSV
regex
sqlToObject
stack
static
super
treemap
updateTable
writeCSV
java FX
3DCharacterMoving
3DMaterialList
DroneMotor
FlowPane
Hello
KeyCode
KeyMovement
ObservableList
Pane
RotateImage
rotateSphere
android
APIview
listview
ToastTimer
touchMovement
WriteReadFile
spring framework
HelloWorld
RESTful
TomcatServlet
java objects
Apple
starseite
/
lessons
/
se
fx
android
spring
/
star wars api
TomcatServlet
2022-06-17 07:51:58
tags:
spring
tomcat
view source
TomcatServlet
screenshot
description
source code
create Class
/src/main/java/com/example/springboot/Application.java
import org.apache.catalina.Context; import org.apache.catalina.LifecycleException; import org.apache.catalina.Wrapper; import org.apache.catalina.startup.Tomcat; public class Application { public static void main(String[] args) throws LifecycleException { Tomcat tomcat = new Tomcat(); tomcat.setPort(8080); tomcat.getConnector(); Context ctx = tomcat.addContext("", null); Wrapper servlet = Tomcat.addServlet(ctx, "TestServlet", new NewServlet()); servlet.setLoadOnStartup(1); servlet.addMapping("/*"); tomcat.start(); } }
create Class
/src/main/java/com/example/springboot/Servlet.java
import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.IOException; public class NewServlet extends HttpServlet { @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException { if (req.getRequestURI().equals("/")) { resp.setContentType("text/html"); resp.getWriter().print("test"); } else { throw new IllegalStateException("Help, I don't know what to do with this url"); } } }