<!-- Login Page -->
<!DOCTYPE html>
<html>
<head>
<meta charset="EUC-KR">
<title>Login</title>
</head>
<body>
<form action="./LoginAction" method=POST>
id: <input name="id" type="text" value="" placeholder="your id."><br>
pwd: <input name="pwd" type="password" value="" placeholder="your password.">
<input type="submit" value="OK!">
</form>
</body>
</html>
<!-- Login Complete Page -->
package com.javachobo;
import java.io.IOException;
import java.io.PrintWriter;
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("/LoginAction")
public class LoginAction extends HttpServlet {
private static final long serialVersionUID = 1L;
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
PrintWriter out = response.getWriter();
String id = request.getParameter("id");
String pwd = request.getParameter("pwd");
request.setCharacterEncoding("EUC-KR");
// out.println("<!DOCTYPE html>");
// out.println("<html>");
// out.println("<head>");
// out.println("</head>");
// out.println("<body>");
out.println("<h1>Your id is "+id+".</h1>");
out.println("<h2>Your Password is "+pwd+".</h2>");
// out.println("</body>");
// out.println("</html>");
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doGet(request, response);
}
}
request.setCharaterEncoding() 메서드를 이용해서 넘겨받는 값을 인코딩 해준다.
이걸 잘 써야 한글로 넘겨도 한글로 받을 수 있다.
인코딩이 잘 안된다면 이 메서드의 위치를 재주껏 조절해서 다시 시도 해보자
'Coding > Servlet & JSP' 카테고리의 다른 글
| javax.net.ssl.SSLException: Received fatal alert: protocol_version (0) | 2018.12.04 |
|---|---|
| 주사위 돌리기 (0) | 2018.01.10 |
| 별찍기 (0) | 2018.01.10 |
| Tomcat v8.5 설치 (0) | 2018.01.10 |