<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<h1>배경색 바꾸기</h1>
<form action="ex07changeBg">
<input type = "color" name="color">
<input type = "submit" value="변경">
</form>
</body>
</html>
html 실행화면
html에 데이터 값 보낸 결과
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("/ex07changeBg")
public class ex07changeBg extends HttpServlet {
private static final long serialVersionUID = 1L;
protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String color = request.getParameter("color");
response.setContentType("text/html; charset=utf-8");
PrintWriter out = response.getWriter();
out.print("<html>");
out.print("<head> </head>");
out.print("<body bgcolor = "+color+">");
out.print("</body>");
out.print("</html>");
}
}
'Java > JSP&Servlet' 카테고리의 다른 글
[Servlet] 배경 색 지정과 구구단 출력하기 (0) | 2022.05.13 |
---|---|
[Servlet] 구구단 출력 (0) | 2022.05.13 |
[Servlet] 배경 색 값 전달받기 (0) | 2022.05.12 |
[Servlet] 두 수의 합 (html에서 입력 받아 자바에서 출력) (0) | 2022.05.12 |
[Servlet] form태그 (html에서 자바로 데이터 보내기) (0) | 2022.05.12 |