Notice
Recent Posts
Recent Comments
Link
Tags
- UnCrackable
- Android Backup
- UnCrackable level 1
- Hackthebox cat
- CVE-2022-22965
- NoSQL
- XALZ 압축해제
- CVE-2014-0094
- mstg
- HackTheBox
- SeeTheSharpFlag
- xss
- CVE-2010-1622
- Frida
- nginx
- JSP
- Android 6.0
- Directory traversal
- Xamarin 분석
- getCachedIntrospectionResults
- mongoDB
- JAVA ClassLoader 취약점
- File Upload
- DOM
- MariaDB
- PortSwigger
- HacktheBox Mobile
- blind sql injection
- HackTheBox APKey
- login form
Archives
- Today
- Total
끄적끄적
[GET/POST] 웹 서버 구축하기 (6) 본문
개요
서블릿 프로그래밍 연습
- 사용자 입력 받기(GET/POST)
환경
- WAS Server: CentOS Linux release 7.9 - Tomcat
관련 경로
servlet-api 라이브러리 | /[Tomcat Directory]/java/tomcat-servlet-api.jar |
ROOT Directory | /[Tomcat Directory]/tomcat/webapps/ROOT/ |
실습
예제코드 작성
사용자 입력을 받는 HTML 코드 작성(GET)
hello.html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert Title Here</title>
</head>
<body>
<form action="hi"> <!--/hi 경로로 전송-->
<div>
<label>입력 횟수</label>
</div>
<div>
<input type="text" name="cnt"/> <!--cnt에 값을 담아-->
<input type="submit" value="출력"/>
</div>
</form>
</body>
</html>
index.jsp 파일 수정
index.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%-- 브라우저에서 인코딩 방식 설정 --%>
<html>
<head>
<title>Redirection</title>
<meta charset="UTF-8">
</head>
<body>
<a href="hello.html">테스트 페이지</a><br>
<a href="login.jsp">로그인 페이지 화면</a><br>
</body>
</html>
사용자 입력을 받는 HTML 코드 작성(POST)
reg.html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert Title Here</title>
</head>
<body>
<form action="notice-reg" method="POST"> <!--/notice-reg로 POST 방식으로 전송, Default는 GET-->
<div>
<label>제목:</label><input name="title" type="text">
</div>
<div>
<label>내용:</label>
<textarea name="content"></textarea>
</div>
<div>
<input type="submit" value="등록"/>
</div>
</form>
</body>
</html>
notice-reg 경로에 맞는 서블릿 코드 작성
NoticeReg.java
import javax.servlet.annotation.WebServlet;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
@WebServlet("/notice-reg")
public class NoticeReg extends HttpServlet
{
@Override
public void service(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
{
response.setCharacterEncoding("UTF-8");
response.setContentType("text/html; charset=UTF-8");
PrintWriter out = response.getWriter();
String title = request.getParameter("title");
String content = request.getParameter("content");
out.println(title);
out.println(content);
}
}
index.jsp에 파일 경로 추가
index.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%-- 브라우저에서 인코딩 방식 설정 --%>
<html>
<head>
<title>Redirection</title>
<meta charset="UTF-8">
</head>
<body>
<a href="hello.html">Integer_GET 테스트 페이지</a><br>
<a href="reg.html">String_POST 테스트 페이지(Refelcted XSS 발생)</a><br>
<a href="login.jsp">로그인 페이지 화면</a><br>
</body>
</html>
Make_NoticeReg.sh
#!/bin/bash
javac -classpath /usr/share/java/tomcat-servlet-api.jar NoticeReg.java
mv ./NoticeReg.class ./WEB-INF/classes
systemctl restart tomcat
결과: 한글 입력 시 한글이 깨짐
Reference
더보기
[1] https://www.youtube.com/watch?v=LKD4FMTx84k
'Development > JSP' 카테고리의 다른 글
[Application, Session] 웹 서버 구축하기 (8) (0) | 2021.11.30 |
---|---|
[Encoding, Servlet Filter] 웹 서버 구축하기 (7) (0) | 2021.11.24 |
[Servlet Programing] 웹 서버 구축하기 (5) (0) | 2021.11.22 |
[Encoding(Response)] 웹 서버 구축하기 (4) (0) | 2021.11.22 |
[Java Compile] 웹 서버 구축하기 (3) (0) | 2021.11.19 |
Comments