LoginSignup
1
1

スッキリわかるサーブレット&JSP

Posted at

学習振り返り

現在10章のdokoTubuを製作中

3章まとめ

1章、2章ではサーブレット、JSPにあまり触れないので3章から開始
まずはeclipseでServletの作成

package servlet;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
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 javax.servlet.http.HttpSession;


@WebServlet("/Login")
public class Login extends HttpServlet {
	private static final long serialVersionUID = 1L;
 
	protected void doPost(HttpServletRequest request, HttpServletResponse response)
		    throws ServletException, IOException {

このソース自体は特に覚える必要なし(勝手に作られるので)
ただ do Getにするのか

protected void doGet(HttpServletRequest request, HttpServletResponse response)
		    throws ServletException, IOException {

doPostにするのかの理解は必要

protected void doPost(HttpServletRequest request, HttpServletResponse response)
		    throws ServletException, IOException {

GetETリクエストとPOSTリクエストの使い分け

Geリクエスト
→リクエストパラメーターが、情報を取得するために場合(例:検索など)
Postリクエスト
→リクエストパラエーターが、情報の登録に利用される場合(例:ユーザー登録やフォームボタンの送信ボタンなどで使われる)
Postリクエスト何かを登録、更新する際に使用するイメージ

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1