본문으로 바로가기

EL(Expression Language)

category 프로그래밍/jsp 2017. 12. 19. 19:50

EL(Expression Language), 표현식 또는 액션 태그를 대신해서 값을 표현하는 언어 입니다.


<%= value %> --------> S{value}



1.우선 setter와 getter를 통해 저장할 class클래스를 생성

package com.javalec.ex;


public class MemberInfo {


private String name;

private String id;

private String pw;

public String getName() {

return name;

}

public void setName(String name) {

this.name = name;

}

public String getId() {

return id;

}

public void setId(String id) {

this.id = id;

}

public String getPw() {

return pw;

}

public void setPw(String pw) {

this.pw = pw;

}

}


2. jsp파일에서 자바빈을 사용하여 set,get를 하여 값을 얻는다.

expressel.jsp 



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

    pageEncoding="EUC-KR"%>

<jsp:useBean id="member" class="com.javalec.ex.MemberInfo" scope="page" />

<jsp:setProperty name="member" property="name" value="홍길동"/>

<jsp:setProperty name="member" property="id" value="abc"/>

<jsp:setProperty name="member" property="pw" value="123"/>

<!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>

이름 : <jsp:getProperty name="member" property="name"/><br />

아이디 : <jsp:getProperty name="member" property="id"/><br />

비밀번호 : <jsp:getProperty name="member" property="pw"/><br />

<hr />

이름 : ${member.name }<br />   //${name. property}

아이디 : ${member.id }<br />

비밀번호 : ${member.pw }<br />

</body>

</html>




내장 객체

pageScope : page객체를 참조하는 객체

requestScope : request객체를 참조하는 객체

sessionScope : session객체를 참조하는 객체

applicationScope : application객체를 참조하는 객체


param : 요청 파라미터를 참조하는 객제

paramValues : 요청 파라미터(배열)참조하는 객제

initParam : 초기화 파라미터를 참조하는 객체

cookie : cookie객체를 참조하는 객체


objel.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 action="objelOk.jsp" method="get">

아이디 : <input type="text" name="id"><br />

비밀번호 : <input type="password" name="pw">

<input type="submit" value="login">

</form>

<% 

application.setAttribute("application_name", "application_value");// 모든 어플리케이션의 name, value지정

session.setAttribute("session_name", "session_value");;// 세션의 name, value지정

pageContext.setAttribute("page_name", "page_value");;// 페이지 범위내 name, value지정

request.setAttribute("request_name", "request_value");;// 요청한 페이지내 name, value지정

%>

</body>

</html>



web.xml

<?xml version="1.0" encoding="UTF-8"?>

<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">

  <display-name>jsp_23_3_ex1_elex</display-name>

  <welcome-file-list>

    <welcome-file>index.html</welcome-file>

    <welcome-file>index.htm</welcome-file>

    <welcome-file>index.jsp</welcome-file>

    <welcome-file>default.html</welcome-file>

    <welcome-file>default.htm</welcome-file>

    <welcome-file>default.jsp</welcome-file>

  </welcome-file-list>

  

  <context-param>

  <param-name>con_name</param-name>

  <param-value>con_name은 홍길동 입니다.</param-value>

  </context-param>

  <context-param>

  <param-name>con_id</param-name>

  <param-value>con_id는 abcde 입니다.</param-value>

  </context-param>

  <context-param>

  <param-name>con_pw</param-name>

  <param-value>con_pw는 12345 입니다.</param-value>

  </context-param>

  

</web-app>



objelOK.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>

<%

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

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

%>

아이디 : <%= id %> <br />

비밀번호 : <%= pw %>

<hr />

아이디 : ${ param.id } <br />

비밀번호 : ${ param.pw } <br />

아이디 : ${ param["id"] } <br />

비밀번호 : ${ param["pw"] }

<hr />

applicationScope : ${ applicationScope.application_name }<br /> //어플리케이션.setAtrribute를 통해 설정한 값을 출력할때는 Scope를 사용한다. 여기서는 name를 출력


sessionScope : ${ sessionScope.session_name }<br />//session.setAtrribute를 통해 설정한 값을 출력할때는 Scope를 사용한다. name을 출력

pageScope : ${ pageScope.page_name }<br />/pageSope.setAtrribute를 통해 설정한 값을 출력할때는 Scope를 사용한다. name을 출력

requestScope : ${ requestScope.request_name }/requestScope.setAtrribute를 통해 설정한 값을 출력할때는 Scope를 사용한다. name을 출력

<hr />

context 초기화 파라미터<br />

${ initParam.con_name } <br />//web.xml에서 설정한 value값을 가져옴

${ initParam.con_id } <br />

${ initParam.con_pw } <br />

</body>

</html>

'프로그래밍 > jsp' 카테고리의 다른 글

url-pattern FrontController패턴  (487) 2018.01.02
JSTL  (506) 2017.12.31
파일업로드  (484) 2017.12.18
19.데이터베이스-3 (회원가입 및 회원정보 프로그래밍)  (468) 2017.12.09
20. 커넥션풀(DAO,DTO, PrepaaredStatement, 커넥션풀)  (487) 2017.12.08