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.
First, create a dynamic web project.
Select File menu → New → Dynamic Web Project.
Give it a project name and you're done.
After confirming that the project has been created, add the dynamic web project to the server so that it can be executed.
Select the project you created earlier from the available locations → "Add". Put it in the configured one and you're done.
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).
This completes the dynamic web project. Next, we will start creating 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.
Once you've decided on your Java package and class name, you're done.
The name of the servlet this time is Mainservlet.
** 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.
Call Secondservlet from the link in index.jsp
Secondservlet
Run on server When you press the link ... Since the following result is obtained, the Servlet call from JSP is completed.
Create css folder and exam.css file in Webcontent
Paste the following link in index.jsp and read the css file
exam.css
As a result, I was able to change the color of h1.
Create JS folder and exam.js file in Webcontent
Put a link to read JS in index.jsp.
exam.js
Check the result. Choose right-click verification.
Confirm if there is something entered in Console.log in Console
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