[JAVA] [JSP, Servlet] Launch a new project and check the connection !!

Launch new project ~ Confirm connection

This time, we will create a web application using ** JSP and Servlet **. This section describes how to create a dynamic Web project (JSP, Servlet) ** and ** Connection confirmation **.

The reason why ** connection confirmation ** is necessary is ... This is to check the connection and make sure it works well before getting into full-scale application production.

The connection confirmation targets are as follows.

** Connection confirmation target **

--Servlet call (data pass) from JSP --CSS (check if it applies) --JS (Check if it is output to the console log) --MySQL connection check

Let's take a look at each one after launching the project.

Create a dynamic web project in Eclipse

First, create a dynamic web project.

Select File menu → New → Dynamic Web Project.

image.png

Give it a project name and you're done.

image.png

After confirming that the project has been created, add the dynamic web project to the server so that it can be executed.

image.png

Select the project you created earlier from the available locations → "Add". Put it in the configured one and you're done.

image.png

Start the server for the dynamic web project you added to take effect.

Select the server in the server view → right-click → start (if it is already running, select restart to restart it). image.png

This completes the dynamic web project. Next, we will start creating JSP and Servlet.

Creation of JSP and Servlet

Create JSP and Servlet.

See below for how to create a JSP and details: point_down_tone2: What is JSP? ~ Let's know the basics of JSP !! ~

** How to create Servlet ** Select File menu → New → Servlet. image.png

Once you've decided on your Java package and class name, you're done. image.png

The name of the servlet this time is Mainservlet.

image.png

** About web annotation **

@WebServlet ("/ URL pattern") http://<サーバー名>/<アプリケーション名>/<URLパターン>

The string inside the WebServlet annotation is added to the end of the URL.

Example (for the above project)

@WebServlet("/Mainservlet")

http://localhost:8090/ConnectSample/Mainservlet

The character string in the URL pattern can be set freely.

@WebServlet("/")

For example, if you change the content of the annotation as shown above, that Servlet becomes the entry point.

Connection confirmation

Servlet call (data passing) from JSP

Call Secondservlet from the link in index.jsp

image.png

Secondservlet

image.png

Run on server image.png When you press the link ... Since the following result is obtained, the Servlet call from JSP is completed.

image.png

CSS (check if it applies)

Create css folder and exam.css file in Webcontent

image.png

Paste the following link in index.jsp and read the css file image.png

exam.css image.png

As a result, I was able to change the color of h1. image.png

JS (check if it is output to the console log)

Create JS folder and exam.js file in Webcontent

image.png

Put a link to read JS in index.jsp. image.png

exam.js image.png

Check the result. Choose right-click verification. image.png

Confirm if there is something entered in Console.log in Console image.png

MySQL connection check

Finally, check the DB connection. See this article for MySQL connectivity: point_down_tone2: [Java] I definitely want to connect MySQL !!! ~ About getting JDBC driver and JAR file location ~

Confirmation is now complete.

Recommended Posts

[JSP, Servlet] Launch a new project and check the connection !!
[Rails] Launch a new project
A Simple CRUD Sample Using Java Servlet / JSP and MySQL
Install Rails in the development environment and create a new application
[Rails] Creating a new project with rails new
Creating a Servlet in the Liberty environment
[Introduction to JSP + Servlet] A little animation ♬
Find out about Rails hidden_field (create a confirmation screen and check the behavior)