2010. 7. 6. 21:48 JAVA , JSP

el 표현식

package el.domain;

public class User {
 
 private String name;

 public String getName() {
  return name;
 }

 public void setName(String name) {
  this.name = name;
 }
 
 

}


<%@ page language="java" contentType="text/html; charset=EUC-KR"
    pageEncoding="EUC-KR"%>
<%@ page import="el.domain.*" %>  
<%@ page import="java.util.*" %> 
<!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>
<%
 //User 객체 생성
 User user = new User();
 user.setName("홍길동");
 
 request.setAttribute("user", user);
 
 
%>

User' name : ${requestScope.user.name } <br />
User' name : ${user.name } <br />

<%
 //세션의 정보를 저장
 String[] list = {"ko", "jp", "uk", "us"};
 session.setAttribute("list", list);
 Map map = new HashMap();
 map.put("kim", "김");
 map.put("lee", "이");
 session.setAttribute("map", map);
 
%>

<a href="el02.jsp">배열이나 컬렉션을 사용한 EL</a>
</body>
</html>

<%@ 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>
 <ul>
  <li>국가코드 : ${list[0] }</li>
  <li>국가코드 : ${list[1] }</li>
  <li>국가코드 : ${list["1"] }</li>
  <li>성 : ${map["kim"] }</li>
  <li>성 : ${map.lee }</li>
  <li>성 : ${map["kim"] }</li>
  <li>성 : ${map[kim] }</li>
 </ul>
</body>
</html>

package el;

public class Toy {
 
 private String name;

 public String getName() {
  return name;
 }

 public void setName(String name) {
  this.name = name;
 }
 
 

}


package el;

public class Dog {
 
 private Toy[] toys;
 private String name;
 public Toy[] getToys() {
  return toys;
 }
 public void setToys(Toy[] toys) {
  this.toys = toys;
 }
 public String getName() {
  return name;
 }
 public void setName(String name) {
  this.name = name;
 }
 
 

}


package el;

public class Person {
 
 private String name;
 private Dog dog;
 public String getName() {
  return name;
 }
 public void setName(String name) {
  this.name = name;
 }
 public Dog getDog() {
  return dog;
 }
 public void setDog(Dog dog) {
  this.dog = dog;
 }
 
 

}


package el;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


public class ELExam01 extends HttpServlet {
 private static final long serialVersionUID = 1L;
  
 
 protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  // TODO Auto-generated method stub
  // 홍길동, 순둥이, 토마스, 뽀로로 객체들을 만들어서
  // request 객체에 담는다
  // 그리고는 elExam01.jsp로 포워딩
  
  Toy t1 = new Toy();
  t1.setName("뽀로로");
  Toy t2 = new Toy();
  t2.setName("토마스");
  
  Dog d = new Dog();
  d.setToys(new Toy[]{t1, t2});
  d.setName("순둥이");
  
  Person p = new Person();
  p.setDog(d);
  p.setName("홍길동");
  
  request.setAttribute("p", p);
  
  // forwarding
  
  request.getRequestDispatcher("elExam01.jsp").forward(request, response);
  
  //일단 ServletContext가 필요하다
  //ServletContext sc = this.getServletContext();
  
  //포워딩 하는 객체가 필요
  // 이때 절대 주소이다
  //RequestDispatcher rd = sc.getRequestDispatcher("/elExam01.jsp");
  
  //포워딩
  //rd.forward(request, response);
  
  
 }

 

}


<%@ 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>
${p.name }의 개${p.dog.name }의 장난감은 ${p.dog.toys[0].name }, ${p.dog.toys[1].name }입니다.
</body>
</html>

'JAVA , JSP' 카테고리의 다른 글

[자바4] if  (0) 2010.07.09
[자바1] 변수 타입에 따른 결과  (0) 2010.07.09
Controller 분석  (0) 2010.07.06
필터  (0) 2010.07.05
redirect servlet  (0) 2010.07.05
Posted by ▶파이팅◀

블로그 이미지
Let's start carefully from the beginning
▶파이팅◀

태그목록

공지사항

Yesterday
Today
Total

달력

 « |  » 2024.4
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 26 27
28 29 30

최근에 올라온 글

최근에 달린 댓글

글 보관함