When I tried to develop a WEB application with Java, I looked it up and found that I think there will be a lot of articles on web application development using Java EE and Spring Boot. (* Probably the current trend is a matter of course.)
Automatic deployment by combining the above technologies and Maven (or Gradle) I think there are many people who want to try it.
However, when I tried to build a development environment by combining the above, A lot of errors occur in unexpected places, Even though the server is running, the response status of "404 Not Found" is returned, On the contrary, I think that there will be many addictive points.
So, first of all, using pure "Apache Tomcat" and "Java Servlet" I thought about developing a web application and displaying the screen.
You can use JavaEE or Spring Boot, try using Maven, and then extend it.
-Eclipse IDE for Enterprise Java Developers -Apache Tomcat v8.0
(1) Create a dynamic WEB project from Eclipse by following the steps below. "File"-> "New"-> "Dynamic WEB Project"
(2) You can name the project as you like, as you see this article. Here, let's call it "hello world".
(3) Regarding the target runtime, I think that it is "Apache Tomcat v7.0" by default. "Apache Tomcat v7.0" does not support Java EE 7, so Here, let's download and install "Apache Tomcat v8.0" from the new runtime. ④ If you advance the screen, you will see the following screen. Here, select "Download and install".
※Caution※ After this, I specified the directory and the download and installation started. Create a new folder (apache-tomcat-8.0) in the eclipse directory in advance, Make sure to download & install there. If you don't do this, the folder structure will be messed up.
⑤ When the installation of Apache Tomcat is completed, the "Finish" button will be activated. Click the "Finish" button to complete the project creation.
① Open the "hellow old" package, right-click the "Java resource-> src" directory, and click Click "New-> Class". At that time, please change the name to "Hello World".
③ Click the Finish button and you can confirm that "HelloWorld.java" is created.
HelloWorld.java
package helloworld;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
/**
*A class that displays "Hello World" on the screen
*/
@WebServlet("/helloworld01")
public class HelloWorld extends HttpServlet {
private static final long serialVersionUID = 1L;
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.getWriter().write("Hello World!");
}
}
④ Right-click the "hello world" package and select "Export-> WAR File". Please create "helloworld.war". (* The output destination can be anywhere.)
(1) From here, let's create a new "Apache Tomcat v8.0" server using Eclipse. I think there is a "server" tag in Eclipse. Please click here.
② Click Create New Server, set the server type to "Apache Tomcat v8.0", and ** * * Please do not change the settings and just "quit". * *** (Please do not worry about the selection of configured resources after clicking "Next" here. I think that setting it will interfere with the understanding of this manual. )
③ I'd like to start the created server, but please get acquainted with the settings a little more. Right-click on the created server and select "Properties" to move to the screen below.
④ Here, I think that the location is the initial value ** "Works Space Metadata" **, so Please switch the location and switch the location to "/ *** / Tomcat of localhost" as above. (Then apply and close)
⑤ After that, double-click the server and refer to the image below to make the settings.
⑥ After this, the server is finally started! Right-click on the server and press "Start". (* Please apply when a message prompting you to save the server changes appears)
(7) When the server startup is complete, try typing the following URL on your browser. It is OK if the management screen of Apache Tomcat is displayed. http://localhost:8080/
① After that, it is a flow to deploy the created WAR file to Apache Tomcat. To deploy, click the ** "Manager App" ** button on the right side of the above screen. The user authentication screen is displayed and I don't think I can proceed. These settings are set as follows from the directory where "Apache Tomcat v8.0" is installed. -Tomcat-users.xml (* in the conf directory)
First, let's open the above file.
(2) I think there is the following description on the 33rd to 39th lines.
[Before setting]
<!--
<role rolename="tomcat"/>
<role rolename="role1"/>
<user username="tomcat" password="<must-be-changed>" roles="tomcat"/>
<user username="both" password="<must-be-changed>" roles="tomcat,role1"/>
<user username="role1" password="<must-be-changed>" roles="role1"/>
-->
③ <-and-> are commented out, so delete them. Overwrite all the remaining parts with the following [After setting]. (Because there are various restrictions ...)
[After setting]
<role rolename="tomcat"/>
<role rolename="role1"/>
<role rolename="manager-gui"/>
<role rolename="manager-status"/>
<role rolename="manager-script"/>
<role rolename="manager-jmx"/>
<role rolename="admin-gui"/>
<role rolename="admin-script"/>
<user username="tomcat" password="s3cret" roles="tomcat"/>
<user username="both" password="s3cret" roles="tomcat,role1"/>
<user username="role1" password="s3cret" roles="role1"/>
<user username="manager" password="s3cret" roles="manager-gui,manager-status,manager-script,manager-jmx"/>
<user username="admin" password="s3cret" roles="admin-gui,admin-script"/>
④ After rewriting after setting, save "tomcat-users.xml".
(5) Now that the user settings have been completed, right-click the server and click "Resume" (* restart the server).
(4) When the Apache Tomcat management screen opens, click ** "Manager App" ** and authenticate with the following. User: manager Password: s3cret
⑤ I think that the page transition will be done correctly. [Supplement] With this setting, the following buttons can be authenticated by the following users. Please take a look at other pages at another time. (* Password is fixed to s3cret) -"Server Status" button ⇒ Use user "manager" -"Manager App" button ⇒ Use user "manager" -"Host Manager" button ⇒ Use user "admin"
⑥ When the "Manager App" screen opens, from the following in the middle Select "helloworld.war".
⑦ Click the "Deploy" button to complete the deployment! Now, if you look at the following URL on your browser ... http://localhost:8080/helloworld/helloworld01
You can safely display "Hello World!"!
This time, I tried to create a server application by scratch. It didn't work because a server error occurred or the screen displayed "404 Not Found".
Of course, if you look it up, you will find solutions for each. Regarding the points I was addicted to this time, I couldn't find a site that was all in one site, so This article was created.
I hope it will be helpful for those who are addicted to the cause of similar errors.
Recommended Posts