본문 바로가기
개발/jsp

jsp request 메소드 사용

by 카앙구운 2015. 9. 24.
728x90
반응형

@함수사용하기2

----------------------------------------------------------------

<%@ page language="java" contentType="text/html; charset=EUC-KR"

    pageEncoding="EUC-KR"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<%!

public int add(int a, int b){

int c=a+b;

return c;

}


public int substract(int a, int b){

int c=a-b;

return c;

}

%>


<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">

<title>Insert title here</title>

</head>

<body>

<%

int Value1=3;

int Value2=9;

int addResult=add(Value1,Value2);

int substrackResult=substract(Value1, Value2);

%>

<%=Value1 %> + <%=Value2 %> = <%=addResult %>

<br>

<%=Value1 %> - <%=Value2 %> = <%=substrackResult %>

</body>

</html>

================================================================

@request로 받아 올 수 있는 것

----------------------------------------------------------------

<%@ page language="java" contentType="text/html; charset=EUC-KR"

    pageEncoding="EUC-KR"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">

<title>Insert title here</title>

</head>

<body>

클라이언트IP<%=request.getRemoteAddr() %><br>

요청한정보길이<%=request.getContentLength() %><br>

요청정보 인코딩<%=request.getCharacterEncoding() %><br>

요청정보 컨텐트타입<%=request.getContentType() %><br>

요청정보 프로토콜<%=request.getProtocol() %><br>

요청정보 전송방식<%=request.getMethod() %><br>

요청URI<%=request.getRequestURI() %><br>

컨텍스트 경로<%=request.getServerName() %><br>

서버포트<%=request.getServerPort() %><br>



</body>

</html>

================================================================@데이터를 입력하면 화면에 뿌려주는 예시1 makeTestForm.jsp

----------------------------------------------------------------

<%@ page language="java" contentType="text/html; charset=EUC-KR"

    pageEncoding="EUC-KR"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">

<title>Insert title here</title>

</head>

<body>

폼에 데이터를 입력 후 '전송 '버튼을 누르세요

<form method="post" action="../study_jsp/viewParameter.jsp">

이름:<input type="text" name="name" size="10"><br>

주소:<input type="text" name="address" size="30"><br>

좋아하는 동물:

<input type="checkbox" name="pet" value="dog">강아지

<input type="checkbox" name="pet" value="cat">고양이

<input type="checkbox" name="pet" value="pig">돼지

<br>

<input type="submit" value="전송">

</form>

</body>

</html>

================================================================@데이터를 입력하면 화면에 뿌려주는 예시1-1

----------------------------------------------------------------

<%@ page language="java" contentType="text/html; charset=EUC-KR"

    pageEncoding="EUC-KR"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<%

request.setCharacterEncoding("euc-kr");

%>

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">

<title>Insert title here</title>

</head>

<body>

<b>request.getParameter()메소드 사용</b><br>

name 파마미터<%=request.getParameter("name")%>

address 파라미터 <%=request.getParameter("address") %>

<p>

<b>request.getParameterValue()메소드 사용</b><br>

<%

String[] value=request.getParameterValues("pet");

if(value!=null){

for(int i=0;i<value.length;i++){

%>

<%=value[i] %>

<%

}

}

%>

</body>

</html>



728x90
반응형

'개발 > jsp' 카테고리의 다른 글

jsp URLEncoder  (0) 2015.10.06
jsp 게시판 만들기 1  (0) 2015.09.30
jsp 달력만들기  (0) 2015.09.25
jsp URLEncoder  (0) 2015.09.25
jsp 기초(출력,달력, 함수)  (0) 2015.09.24

댓글