본문 바로가기

JAVA/JSP & Servlet

JSP 기본 실습 : 데이터 전송 받기 -request-

 

<%@ page language="java" contentType="text/html; charset=UTF-8"

    pageEncoding="UTF-8"%>

 

<!DOCTYPE html>

<html>

<head>

<meta charset="UTF-8">

<title>JSP : 데이터 전송 받기[request]</title>

 

<script type="text/javascript">

        function checkFrm() {

               document.frm1.submit();               //submit()

        }

</script>

 

</head>

<body>

 

<form name="frm1" method="post" action="formout_ex02.jsp">

 

검색어 : <input type="text" name="query" size="20" value="한글" /><br/>

비밀번호 : <input type="password" name="password" size="20" value="123" /><br/>

              

<!-- 전송동작 -->              

<input type="submit" value="검색" /><br/>

<input type="image" src="naver_img.gif" /><br/>

<input type="button" value="검색" onclick="checkFrm()" /><br/>

</form>

 

 

</body>

</html>

 

 

 

<%@ page language="java" contentType="text/html; charset=UTF-8"

    pageEncoding="UTF-8"%>

 

<%

        request.setCharacterEncoding("UTF-8");       //한글이 깨지지 않도록 UTF-8으로 받음. getParameter위에 써야함!!

       

        String query = request.getParameter("query");

        String password = request.getParameter("password");

        out.println(query + "<br/>");

        out.println(password + "<br/>");

%>