2011. 1. 27. 11:00


표현언어의 기능
- JSP의 네가지 기본 객체가 제공하는 영역의 속성 사용
   : 네가지 기본객체 - SCOP(session, application,
- 집합 객체(Collection)객체에 대한 접근 방법 제공
- 수치 연산, 관계 연산, 논리 연산자 제공
- 자바 클래스 메서드 호출 기능 제공
- 표현 언어만의 기본 객체 제공

 ${변수명}
 ${메소드호출}
 ${계산}


>EL이 제공하는 11개의 기본 객체

기본객체

설명

pageContext

JSP의 page 기본객체와 동일하다

pageScope

pageContext 기본 객체에 저장된 속성의 <속성, 값>매핑을 저장한

Map 객체

requestScope

request 기본객체에 저장된 속성의 <속성,값>매핑을 저장한

Map객체

sessionScope

session 기본객체에 저장된 속성의 <속성,값>매핑을 저장한

Map객체

applicationScope

application 기본객체에 저장된 속성의 <속성,값>매핑을 저장한

Map객체

param

요청 파라미터의 <파라미터이름,값>매핑을 저장한 MAp객체.

파라미터 값의 타입은 String으로서, request.getParameter(이름)의 결과와 동일하다.

paramValues

요청 파라미터의 <파라미터이름.값배열>매핑을 저장한 Map객체.

값의 타입은 String[]으로서, rerquest.getParameterValues(이름)의 결과와 동일하다.

header

요청 정보의 헤더이름, 값> 매핑을 저장한 Map객체.

request.getHeader(이름)의 결과와 동일하다.

headerValues

요청정보의 <헤어이름, 값>배열 매핑을 저장한 Map객체.

request.getHeaders(이름)의 결과와 동일하다.

cookie

<쿠키 이름,Cookie>매핑을 저장한 Map 객체. request.getCookies()로 구한 Cookie배열로부터 매핑을 생성한다.

initParam

초기화 파라미터의 <이름, 값> 매핑을 저장한 Map 객체. application.getInitParameter(이름)의 결과와 동일하다.






test.jsp


<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!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=UTF-8">
<title>Insert title here</title>
<style type="text/css">
p { color: blue;  font-size: 14pt;}
</style>
</head>
<body>
       <!-- 이런 식으로 실행  http://dddd/test.jsp?name=kim-->
        1.  수신된 데이터: ${param.name} <br/>
        2.  수신된 데이터: <%= request.getParameter("name")%> <br/>
        3.  JSESSIONID 쿠기값 : ${cookie.JSESSIONID.value}
      
</body>
</html>

'Java' 카테고리의 다른 글

파일과 입출력 API  (0) 2011.01.11
java.util 패키지(유틸리티 API)  (0) 2011.01.11
static정리  (0) 2011.01.06
추상클래스 / 인터페이스  (0) 2011.01.06
instanceof연산자  (0) 2011.01.05
Posted by Triany
2011. 1. 25. 15:51














Posted by Triany
2011. 1. 25. 14:48


login 처리의 예!!!

 login.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!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=UTF-8">
<title>Insert title here</title>
</head>
<body>

<form action = "login.do" method  = "post">
사용자명 : <input type = "text" id = "id" name = "id"/><br/>
패스워드 : <input type = "password" id = "passwd" name = "passwd"/><br/>
<input type = "submit" value = "로그인"/>
<input type = "reset" value = "취소"/>
</form>

</body>
</html>

LoginServlet.java

import java.io.IOException;

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

/**
 * Servlet implementation class LoginServlet
 */
public class LoginServlet extends HttpServlet {
 private static final long serialVersionUID = 1L;
      
    /**
     * @see HttpServlet#HttpServlet()
     */
    public LoginServlet() {
        super();
        // TODO Auto-generated constructor stub
    }
   
 protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  // TODO Auto-generated method stub
  request.setCharacterEncoding("utf-8");
  String id = request.getParameter("id");
  String passwd = request.getParameter("passwd");
  if( id != null && id.equals("kim") &&
    passwd != null && passwd.equals("123")){
   String message = id +"님 환영합니다.";
   request.setAttribute("message", message);
   RequestDispatcher patcher =
    request.getRequestDispatcher("success.jsp");
   patcher.forward(request, response);
   return;
  }else{
   String message = "로그인 실패";
   request.setAttribute("message", message);
   RequestDispatcher patcher =
    request.getRequestDispatcher("failed.jsp");
   patcher.forward(request, response);
   return;
  }
  
  
 }


 /**
  * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
  */
 protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  // TODO Auto-generated method stub
 }

 /**
  * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
  */

}

sucess.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!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=UTF-8">
<title>Insert title here</title>
</head>
<body bgcolor = "green">
   <b1><font color = "white" size = "6" >
   <%= request.getAttribute("message") %></b1>

</body>
</html>

failed.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!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=UTF-8">
<title>Insert title here</title>
</head>
<body bgcolor = "red">
  <b1><font color = "white" size = "6" >
   <%= request.getAttribute("message") %></b1>
</body>
</html>





index.jsp

 <%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!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=UTF-8">
<title>Insert title here</title>
<link rel = "stylesheet" href = "login.css" type = "text/css"/>
</head>
<body>
   <div id="container">
 <div id="header">
  <h1>
   HomeShopping♡
  </h1>
 </div>
 <div id="navigation">
  <ul>
   <li><a href="#">홈으로</a></li>
   <li><a href="#">거래내역</a></li>
   <li><a href="#">장바구니</a></li>
   <li><a href="#">개인정보</a></li>
  </ul>
 </div>
 <div id="content-container">
  <div id="content">
   <h2>
     Hello!!!
   </h2>
   <p>
    Lorem ipsum dolor sit amet consect etuer adipi scing elit sed diam nonummy nibh euismod tinunt ut laoreet dolore magna aliquam erat volut. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi.
   </p>
   <p>
    Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.
   </p>
   <p>
    Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat.
   </p>
  </div>
  <div id="aside">
   <jsp:include page = "login.jsp"/> 
  </div>
  <div id="footer">
   Copyright © Site name, 20XX
  </div>
 </div>
</div>
</body>
</html>

 login.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!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=UTF-8">
<title>Insert title here</title>
</head>
<body>
<% if (session.getAttribute("username") == null ) {%>
<form action = "login.do" method  = "post">
사용자명 : <input type = "text" id = "id" name = "id"/><br/>
패스워드 : <input type = "password" id = "passwd" name = "passwd"/><br/>
<input type = "submit" value = "로그인"/>
<input type = "reset" value = "취소"/>
</form>
<%} else { %>
<p><%= session.getAttribute("username") %> 님 환영합니다. </p>
<p><a href = "logout.jsp"> 로그아웃</a> &nbsp;
   <a href = "mod_user_info.jsp">정보수정</a></p>
<% } %>
</body>
</html>
 




 

logout.jsp 

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<% session.invalidate(); %>
<script language = "javascript">
 alert("성공적으로 로그아웃하였습니다.");
 location.href = "index.jsp";
</script language>

login.css
 @CHARSET "UTF-8";
#sidebar{ float:right; width:245px;}
/* 로그인 */
#login {width:208px; height:128px; background:url(standard/images/bg_login.jpg) no-repeat; margin-bottom:10px; padding:47px 17px 0 20px;} /*패딩때문에 높이와 너비가 줄었음 */
#login dd{width:141px; float:left; vertical-align:top;}
#login dd.pw{ margin-top:3px;}
#login .input_text{border:1px solid #c9c9c9; width:137px; height:18px; color:#444;}
#login #id{background:#fff url(images/bg_login_id.gif) no-repeat 0px 0px;}
#login #pw{background:#fff url(images/bg_login_pw.gif) no-repeat 0px 0px;}
#login .keeping{float:right; margin:-22px 0 0 0; background:#003366}
#login .log_in_etc{float:left; padding:5px 0 0 0; .padding:3px 0 0 0; color:#9e9e9e; font:normal 11px dotum; width:170px;}
#login .log_in_etc input{ vertical-align:-2px; margin:0 3px 0 0;}
#login .log_in_find {float:left; clear:both; margin-top:14px;.margin-top:9px; font-size:12px; width:200px; letter-spacing:-1px;}
#log_notice {float:left; clear:both;width:200px; margin-top:16px;.margin-top:13px;font:normal 11px dotum; } /*.margin은 IE6의 공백을 맞추기위해 핵사용*/
#log_notice img{ vertical-align:-1px;}

 

 

#container
{
 margin: 0 auto;
 width: 900px;
 background: #ffc0cb;
}

#header
{
 background: #ffb6C1;
 padding: 20px;
}

#header h1 { margin: 0; }

#navigation
{
 float: left;
 width: 900px;
 background: #bc8f8f;
}

#navigation ul
{
 margin: 0;
 padding: 0;
}

#navigation ul li
{
 list-style-type: none;
 display: inline;
}

#navigation li a
{
 display: block;
 float: left;
 padding: 5px 10px;
 color: #fff;
 text-decoration: none;
 border-right: 1px solid #fff;
}

#navigation li a:hover { background: #383; }

#content-container
{
 float: left;
 width: 900px;
 background: #ffe4f1 url(/wp-content/uploads/layout-two-fixed-background.gif) repeat-y 100% 0;
}

#content
{
 clear: left;
 float: left;
 width: 560px;
 padding: 20px 0;
 margin: 0 0 0 30px;
 display: inline;
}

#content h2 { margin: 0; }

#aside
{
 float: right;
 width: 240px;
 padding: 20px 0;
 margin: 0 20px 0 0;
 display: inline;
}

#aside h3 { margin: 0; }

#footer
{
 clear: left;
 background: #ffdab9;
 text-align: right;
 padding: 20px;
 height: 1%;
}

 LoginServlet.java
package simple.web.controller;

import java.io.IOException;

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

/**
 * Servlet implementation class LoginServlet
 */
public class LoginServlet extends HttpServlet {
 private static final long serialVersionUID = 1L;
      
    /**
     * @see HttpServlet#HttpServlet()
     */
    public LoginServlet() {
        super();
        // TODO Auto-generated constructor stub
    }
   
 protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  // TODO Auto-generated method stub
  request.setCharacterEncoding("utf-8");
  String id = request.getParameter("id");
  String passwd = request.getParameter("passwd");
  HttpSession session = request.getSession();
  if( id != null && id.equals("kim") &&
    passwd != null && passwd.equals("123")){
   session.setAttribute("username", id);
  }
  RequestDispatcher patcher =
  request.getRequestDispatcher("index.jsp");
  patcher.forward(request, response);
  return;
 }


 /**
  * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
  */
 protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  // TODO Auto-generated method stub
 }

 /**
  * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
  */

}

 











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

JSTL 환경 설정  (0) 2011.01.27
색상테이블 / 색상표 / 색상코드  (0) 2011.01.25
JSP == Servlet (궁극적으로...)  (0) 2011.01.25
JSP 페이지 구성 요소 / 웹 요청 처리 SCOPE  (0) 2011.01.25
서블릿 (ⅱ)  (0) 2011.01.25
Posted by Triany