본문 바로가기

Programming/Servlet & JSP

html에서 servlet으로 값 전달

PrintText.java

package com;

import java.io.IOException;
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("/Result")
public class Result extends HttpServlet {
	protected void service(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		request.setCharacterEncoding("EUC-KR");
		String text = request.getParameter("text");
		System.out.println(text);

	}

}

 

submitText.html

<!DOCTYPE html>
<html>
<head>
<meta charset="EUC-KR">
<title>Insert title here</title>
</head>
<body>
	<form action="Result" method="post">
		<input type="text" name="text">
		<input type="submit">
	</form>
</body>
</html>