テスト用に直接ページに飛べるドライバーをよく作るので、
自分のコピペ用。
色はついてなくても良いけど、ついていると楽しい気分になるから。
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;
@WebServlet(name = "TestServlet", urlPatterns = {"/TestServlet"})
public class TestServlet extends HttpServlet {
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
}
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String next ="";
request.setCharacterEncoding("UTF-8");
String screen = request.getParameter("screen");
switch (screen) {
case "1":
next = "/Test/screen1.jsp";
break;
}
// リダイレクト
response.sendRedirect(next);
// フォワード
// RequestDispatcher dispatch = request.getRequestDispatcher(next);
// dispatch.forward(request, response);
}
}
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!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>Insert title here</title>
<style type="text/css">
<!--
div.driver_input {
width: 640px;
margin:8px 0 0;
padding:8px;
font-size: 12px;
background: #c8d5bb;
/*角丸*/
-webkit-border-radius: 8px;
-moz-border-radius: 8px;
border-radius: 8px;
}
div.driver_submit {
width: 640px;
margin:20px 20px 20px 20px;
}
-->
</style>
</head>
<body>
<form id="test-form" action="/Test/TestServlet" method="post">
<div class="driver_input">
ID:<input type="text" name="id" class="txtfiled" placeholder="">
</div>
<div class="driver_input">
画面:
<select name="screen">
<option>選択してください</option>
<option value="1">画面1</option>
</select>
</div>
<div class="driver_input">
チェックボックス:
<label><input type="checkbox" name="driver-check" value="1" />チェックボックス</label>
</div>
<div class="driver_input">
<label><input type="radio" name="driver-radio" value="1" />1</label>
<label><input type="radio" name="driver-radio" value="2" />2</label>
</div>
<div class="driver_submit">
<input type="submit" value="submit">
<input type="reset" value="reset">
</div>
</form>
</body>
</html>

