When studying how to create a web app, you will come across many words such as JSP, Servlet, form and Post / Get methods. I think it's a place where many words come out at once and it's easy to get confused. Therefore, here we will introduce the Post method using very simple code.
The environment is Eclipse.
The Post method is one of the request methods in a web app. I think it is often introduced with the Get method. The difference between the two lies in how the parameters are passed to the web server. The Post method passes the parameters in the Request area, while the Get method passes them in the URL.
Create a program that transitions to end.jsp by clicking the button from start.jsp. Each code is as follows. Only the part of the body tag is described.
start.jsp
<body>
start
<form method="post" action="end.jsp">
<button>click</button>
</form>
</body>
end.jsp
<body>
end
<a href="start.jsp">back</a>
</body>
The execution result is as follows. If you just want to change the screen, you can use the a tag like end.jsp. However, it is possible to send parameters to the Web server by specifying Post as method using the form tag like start.jsp. For example, if you create a text box inside the form tag, put characters in the text box and click the button, you can send the input value of the text box to the web server.
-JSP Servlet: Java server-side practice Java language series Nobuyuki Inoue (Author)
Recommended Posts