본문 바로가기
Language/JSP

JSP 내장객체

by 태윤2 2020. 6. 2.

request 내장객체

 

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
 
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
 
<body>
<%
//폼에서 post 방식으로 전송할때 request정보를 사용하기 전에 한글 처리
request.setCharacterEncoding("utf-8");
// 폼에서 전송받은 name 값을 받는 내장객체 request
String name =reqeust.getParameter("name");
%>
<%=name%>
 
 
</body>
cs

 

출력 내장객체 = out

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
 
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
 
<body>
<%
//out 출력 내장객체
String age =request.getParameter("age");
int a = Interger.parseInt(age);
if(a<20){
out.println("미성년입니다" + "<br>" );
}else if (Interger.parseInt(age) >= 20){
    out.println("성입입니다" + "<br>");
}
%>
<%=name%>
 
 
</body>
cs

체크박스를 배열로 저장하기

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
 
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
 
<body>
<%
String[] hobby = request.getParameterValues("hobby");
 
%>
<%if(hobby != null){
    for(int i =0; i<hobby.length ; i++){%><%=i+1%><%=hobby[i]%>
<%}
}
%>
 
 
</body>
cs

 

 

 

 

'Language > JSP' 카테고리의 다른 글

application 내장객체  (0) 2020.06.02
액션태그  (0) 2020.06.02
객체  (0) 2020.06.02
request 내장객체  (0) 2020.06.02
JSP  (0) 2020.06.02