JSP Tutorial 1

김빛나리·2020년 7월 6일
0

1. JSP Introduction

  • WebContent에서 new -> jsp파일 -> 이름 설정
  • body안에 글씨 쓰기
    <body>  </body> 부분
  • 프로젝트인 hello -> run as -> run on server -> jsp에서 작성했던 부분 출력

2. JSP Scripting Elements

  • scriptlet tag
    • <% java source code %>
    • java 코드를 쓸 때에는 꼭 <% %>이 사이에서
  • expression tag
    • <%= statement %>
    • <%= "welcome to jsp" %>
  • declaration tag
    • <%! field or method declaration %>
    • <%! int data=50; %>

3. 9 Implicit Objects

  • Out
    • For writing any data to the buffer, JSP provides an implicit object named out. It is the object of JspWriter. In case of servlet you need to write:
      • PrintWriter out=response.getWriter();
      • in JSP, you don't need to write this code.
    • <% out.print("Today is:" + java.util.Calendar.getInstance().getTime()); %>
      • Today is: 출력
  • Request
    • .html에서 .jsp을 불러오면
    • 처음에 html에서 이름을 입력받고 버튼을 누르면 data와 함께 jsp로 넘어간다.
    • Class (JSP_1)에서 ex1.html & Welcome.jsp 참고
  • Response
    • .html에서 .jsp을 불러오면
    • 처음에 html에서 이름을 입력받고 버튼을 누르면 data와 함께 jsp로 넘어간다.
    • <% response.sendRedirect("http://www.google.com"); %>
    • jsp 파일에는 위의 것이 있어서 넘어온 data와 상관없이 구글 사이트로 넘어감
    • Class (JSP_1)에서 ex6_1.html & ex6_2.jsp 참고
  • Config
    • JSP config implicit object 설명필요
    • xml file필요
    • html에서 data받고 jsp에서
      • String driver=config.getInitParameter("dname");
      • web.xml file에서 "para-name"이 dname을 찾고 "para-value"를 jsp에 보내줌
  • Application
    • config와 비슷
    • String driver=application.getInitParameter("dname");
  • Session
    • The Java developer can use this object to set, get or remove attribute or to get session information.
    • html에서 form작성하고 버튼을 누르면 welcome.jsp로 넘어감
    • "Welcome 이름" 있고 밑에 second.jsp로 넘어가는 링크 있음
    • 누르면 "Hello 이름"
  • PageContext
    • The pageContext object can be used to set,get or remove attribute from one of the following scopes(범위):
      • page
      • request
      • session
      • application
    • In JSP, page scope is the default(기본) scope.
  • Page
    • This object is assigned to the reference of auto generated servlet class. It is written as:
    • Object page=this;
    • <% (HttpServlet)page.log("message"); %> 할 필요없이
    • <% this.log("message"); %> 면 OK
  • Exception
    • This object can be used to print the exception.
    • But it can only be used in error pages.It is better to learn it after page directive.

참고: https://www.javatpoint.com/jsp-tutorial

0개의 댓글