It still doesn't work with this alone From now on, we will link the transition source jsp with the Jakarta Servlet to be started.
[When creating a project in the first step](https://qiita.com/hatopo/items/3cd12bda5d995703c293#%E3%83%97%E3%83%AD%E3%82%B8%E3%82%A7% E3% 82% AF% E3% 83% 88% E4% BD% 9C% E3% 82% 8A% E3% 81% BE% E3% 81% 97% E3% 82% 87% E3% 81% 86), By checking [Generate web.xml deployment descriptor], I think that the following files are created under WEB-INF.
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1">
<display-name>ServletApp</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
</web-app>
Probably the above code is also written automatically, but for the time being, explanation
ServletApp
~ / project name /
is specified instead of ~ / project name / jsp file name
likehttp: // localhost: 8080 / ServletApp /
Specify the file you want to transition to Now, let's add various things under <welcome-file-list>
<servlet>
<servlet-name>login</servlet-name>
<servlet-class>login.LoginServlet</servlet-class>
</servlet>
In <servlet-class>
, specify the relative path of the file you want to call starting from the project folder (ServletApp).
You can call ~ /ServletApp/login/LoginServlet.java
by writing as above.
Give <servlet-name>
a temporary name for this class (use it just below)
<servlet-mapping>
<servlet-name>login</servlet-name>
<url-pattern>/mypage</url-pattern>
</servlet-mapping>
In <url-pattern>
, specify the action path of the form tag of the calling jsp.
The jsp side is / ServletApp / mypage
, but since this is the starting point of the project folder, it will be / mypage
.
For <servlet-name>
, specify the name of the <servlet>
you want to call.
This makes it possible to make screen transitions. The above is a series of flow
Click the green icon on the server
If the server does not appear, open the view with [Window]-[View View]-[Others] on the menu bar and select [Server] to open it.
↑ Like this
Let's specify http: // localhost: 8080 / ServletApp / login.jsp
to display the screen.
(If you specified login.jsp in <welcome-file>
earlier, you can also display it in http: // localhost: 8080 / ServletApp /
, so please try it.
It's too simple, but I was able to see the screen
Try typing hatopo
and pressing the login button ...
You have successfully passed the parameters!
Continue to [Java Servlet] Senri no Michi from one step to the fourth step
Recommended Posts