LoginSignup
0
0

More than 5 years have passed since last update.

おぼえがきdrill12

Posted at
ZodiacServlet4.java
/*【drill12あとやること】
 * ①html。サーブレット共にファイル、パッケージを作成
 * ②year5.html完成させる drill10のHTMLから持ってくる
 * ③xmlにサーブレットのリンクを追記
 *
 */

package drill12;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class ZodiacServlet4 extends HttpServlet {

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp)
            throws ServletException, IOException {
        // TODO 自動生成されたメソッド・スタブ

        String birthYear= req.getParameter("birthYear");
        String msg=null;

        if(birthYear.isEmpty()){
            msg="エラーが発生しました";
            output(resp,msg);
            return;
        }


    }

    public void output(HttpServletResponse resp, String outMsg)throws ServletException, IOException{

        //コンテンツタイプ(日本語表示)の指定
        resp.setContentType("text/html; charset=UTF-8");

        // コメント入力画面出力
        PrintWriter out = resp.getWriter();
        out.println("<html>");
        out.println("<head><title>RedirectServlet</title></head>");
        out.println("<body>");
        out.println(outMsg+"<br>");
        out.println("<a href='/web-drill/htmldrill12/year5.html'>入力画面に戻る</a><br>");//サーブレット教科書p.97.l.37
        out.println("</body>");
        out.println("</html>");
        out.close();
    }

}

year5.html
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>postcode</title>
</head>
<body>
<form method="post" action="/web-drill/ZodiacServlet4">


//②year5.html完成させる drill10のHTMLから持ってくる

</form>
</body>
</html>
0
0
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
0
0