Materials for learning
In a nutshell, it takes a request and returns a response to it. For example, on a general website, a request called URL is sent to the server and html is received as a response. In programming, when you want to create a server, some languages make it easy to set up a server, but when it comes to Java, that's difficult. So, install the one with the server function in advance and create a server in cooperation with it.
Tomcat is a server function that makes it easy to work with Java Servlet. So let's make a simple Servlet. First, open Eclipse. Note that Java EE is blue under the x button in the upper right corner.
Right-click here → New → Dynamic Project to create a Dynamic Project. Since there is a place to set ProjectName and Target runtime, set it. If Tomcat is not installed, you will need to install Tomcat. Assuming that ProjectName is set appropriately, Target runtime selects the version of Tomcat that you have selected and associates it with the downloaded Tomcat file.
Press finish when you have finished setting.
Create a Package with the name main directly under src, and create a new Servlet file with the Class Name Test in it. Both Package creation and Servlet file creation can be performed by right-clicking.
Once created, click below where Servers is written below the image above.
Then click and select the Tomcat version that is the same as the one you first selected in Target Runtime.
You can create a server by pressing Add and then Finish.
After that, click the server and click the bug mark to start the server. By default, hitting localhost: 8080 / sample-project / Test will return a response. Execution result
Recommended Posts