package servlet.redirect;
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 ErrorPronServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
public ErrorPronServlet() {
super();
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doPost(request,response);
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String choose = request.getParameter("choose");
if(choose == null){
//response.sendRedirect("/myweb/redirect/error.html");//절대경로
response.sendRedirect("redirect/error.html");//상대경로 : 실행되는 파일 기준으로 찾아 들어가라.(서블릿의 url기준으로 찾아 들어가야 한다.)
return;
}
response.setContentType("text/html;charset=utf-8");
PrintWriter out = response.getWriter();
out.println("<html><body>");
out.println("체크박스가 체크되어 넘어왔습니다."+choose);
out.println("</body></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>Insert title here</title>
</head>
<body>
<form action="/myweb/error_pron" method="post">
체크 <input type="checkbox" name="choose" value="yes">
<input type="submit" value="전송">
</form>
</body>
</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>Insert title here</title>
</head>
<body>
실행중 오류가 발생했습니다<br>
관리자에게 문의하십시오<br>
관리자 email : admin@abc.com
</body>
</html>