111111 구성모 Struts Tutorial.

Slides:



Advertisements
Similar presentations
CGI programming. Common Gateway Interface interface between web server and other programs (cgi scripts) information passed as environment variables passed.
Advertisements

Struts 2.0.
Java Server Pages (JSP)
Java Servlet & JSP © copyright 2005 SNU OOPSLA Lab.
Server Side Programming Common Gateway Interface (CGI): Scripts generate Web pages or other files dynamically by processing form data and returning documents.
Web MVC-2: Apache Struts Rimon Mikhaiel
CSE 190: Internet E-Commerce Lecture 7. HTML Templates Designed to separate server side logic from HTML presentation Key features –Escapes from HTML into.
An introduction to Java Servlet Programming
18-Jun-15 JSP Java Server Pages Reference: Tutorial/Servlet-Tutorial-JSP.html.
JSP Java Server Pages Reference:
Web programming for project students Dr Jim Briggs.
JSP Architecture  JSP is a simple text file consisting of HTML or XML content along with JSP elements  JSP packages define the interface for the compiled.
Chapter 4 Servlets Concept of Servlets (What, Why, and How) Servlet API Third-party tools to run servlets Examples of Using Servlets HTML tag with GET.
A Servlet’s Job Read explicit data sent by client (form data) Read implicit data sent by client (request headers) Generate the results Send the explicit.
CSCI 6962: Server-side Design and Programming History and Background.
Java Servlets and JSP.
Introduction to Java web programming Dr Jim Briggs JWP intro1.
Gayle J Yaverbaum, PhD Professor of Information Systems Penn State Harrisburg.
Java Servlets & Java Server Pages Brad Rippe Fullerton College.
Servlets. - Java technology for Common Gateway Interface (CGI) programming. - It is a Java class that dynamically extends the function of a web server.
AN OVERVIEW OF SERVLET TECHNOLOGY SERVER SETUP AND CONFIGURATION WEB APPLICATION STRUCTURE BASIC SERVLET EXAMPLE Java Servlets - Compiled By Nitin Pai.
Objectives Java Servlet Web Components
Java support for WWW Babak Esfandiari (sources: Qusay Mahmoud, Roger Impey, textbook)
CSC 2720 Building Web Applications
Chapter 5 Java Servlets. Objectives Explain the nature of a servlet and its operation Use the appropriate servlet methods in a web application Code the.
111 Java Servlets Dynamic Web Pages (Program Files) Servlets versus Java Server Pages Implementing Servlets Example: F15 Warranty Registration Tomcat Configuration.
Basic Struts Architecture Client Server Database Request Response Control View Model Server Struts Framework.
Chapter 7 Java Server Pages. Objectives Explain how the separation of concerns principle applies to JSP Describe the operation and life-cycle of a JSP.
Servlet / JSP 전 혜 영전 혜 영 전 혜 영전 혜 영. 0. 목차  Web Application Technologies  Servlet Server  Simple Servlet  Servlet / HTML Form  Deployment Descriptor.
CMPUT 391 – Database Management Systems Department of Computing Science University of Alberta CMPUT 391 Database Management Systems Web based Applications,
Web Server Programming 1. Nuts and Bolts. Premises of Course Provides general introduction, no in-depth training Assumes some HTML knowledge Assumes some.
Stanisław Osiński, 2002JSP – A technology for serving dynamic web content Java Server Pages™ A technology for serving dynamic web content Stanisław Osiński,
Java Servlets. Servlets When we run small Java programs within a browser these are referred to as Applets... And when we run small Java programs within.
The Simplest Possible Tool - Iteration 1 Vancouver Bootcamp Mike Osterman
Java Servlets & Java Server Pages Lecture July 2013.
20-Nov-15introServlets.ppt Intro to servlets. 20-Nov-15introServlets.ppt typical web page – source Hello Hello.
A seminar on j2ee by saritha. s. What is J2EE J2EE (Java 2 Platform, Enterprise Edition) is a Java platform designed for the mainframe-scale computing.
Java Servlet API CGI / HTTP Concepts Java Servlet API.
Top right corner for field-mark, customer or partner logotypes. See Best practice for example. Slide title 40 pt Slide subtitle 24 pt Text 24 pt Bullets.
JavaServer Page by Antonio Ko. Overview ► Introduction ► What is a servlet? ► What can servlets do? ► Servlets Vs JSP ► Syntax ► Samples ► JavaBean ►
Java Servlets and Java Server Pages Norman White Stern School of Business.
Middleware 3/29/2001 Kang, Seungwoo Lee, Jinwon. Description of Topics 1. CGI, Servlets, JSPs 2. Sessions/Cookies 3. Database Connection(JDBC, Connection.
1 Introduction to Servlets. Topics Web Applications and the Java Server. HTTP protocol. Servlets 2.
Mark Dixon 1 11 – Java Servlets. Mark Dixon 2 Session Aims & Objectives Aims –To cover a range of web-application design techniques Objectives, by end.
Advanced Java Session 6 New York University School of Continuing and Professional Studies.
Configuration Web Server Tomcat - Install JDK Install Tom cat Configure Tom cat for running Servlet C:\Program Files\Apache Software Foundation\Tomcat.
©SoftMoore ConsultingSlide 1 Overview of Servlets and JavaServer Pages (JSP)
Java and the Web CSE 3330 Southern Methodist University.
HTTP protocol Java Servlets. HTTP protocol Web system communicates with end-user via HTTP protocol HTTP protocol methods: GET, POST, HEAD, PUT, OPTIONS,
Java Web Applications. WAR Web Archive Introduced with servlet 2.2 specification Portable deployment mechanism for web applications Defines directory.
Introduction To HTML Dr. Magdi AMER. HTML elements.
How CGI and Java Servlets are Run By David Stein 14 November 2006.
 Java Server Pages (JSP) By Offir Golan. What is JSP?  A technology that allows for the creation of dynamically generated web pages based on HTML, XML,
J2EE/Java EE Apache Tomcat v9 IBM Websphere v8 Redhat JBoss EAP v6 Oracle Weblogic v12 Fusion Web Tier ServletsJSPJSF Business Tier JMXJMSEJB.
Bayu Priyambadha, S.Kom. Static content  Web Server delivers contents of a file (html) 1. Browser sends request to Web Server 3. Web Server sends HTML.
Chapter 2 Java Struct 2. Content Basic MVC Architecture Struts 2 Overview Struts 2 - Architecture.
S ERVLETS Form Data 19-Mar-16. F ORM P ROCESSING You must have come across many situations when you need to pass some information from your browser to.
1 Lecture 8 George Koutsogiannakis/Summer 2011 CS441 CURRENT TOPICS IN PROGRAMMING LANGUAGES.
Spell Checker web service (you build a web client that interacts with the service) The client uses a servlet class and a JSP page. The user passes information.
Java Server Pages Yes it is Java. What you should know HTML Java.
Course Outcomes of Advanced Java Programming AJP (17625, C603)
In Class Assg 3 - Solution
Java Server Pages.
Servlets and Java Server Pages
Servlets and JSP 20-Nov-18 servletsJSP.ppt.
In Class Assg 2 - solution
Representation and Management of Data on the Web
Java Servlets and JSP.
Introduction to Java Servlets
Presentation transcript:

111111 구성모 Struts Tutorial

Presenter ㅎㅇㅎㅇ http://sparcs.org/~breadfish/Struts_tutorial.ppt

Web Application Server HTML JS 웹 서버 (Apache, IIS, …) JPG .

Web Application Server HTML JS 웹 서버 (Apache, IIS, …) CGI DB .

Web Application Server HTML 웹 어플리케이션 서버(WAS) JS 웹 서버 컨테이너 Class DB .

Web Application Server 웹서버 기능 Servlet/JSP 컨테이너 기능 EJB 컨테이너 기능 트랜잭션 서버 보안 서버 네이밍 서버 JDBC 지원 톰캣, RESIN, 웹로직, 웹투비

Why JSP? 실무 .php .jsp .asp .do .action

개발환경구축 mkdir struts_tutorial 톰캣을 설치할 디렉토리 만들기 mkdir struts_tutorial 톰캣7 다운로드 http://mirror.apache-kr.org/tomcat/tomcat-7/v7.0.22/bin/apache-tomcat-7.0.22.tar.gz tar -xvf

개발환경구축 <Server port=“8005” <Connector port=“8080” cd apache-tomcat-7.0.22/bin ./catalina.sh start ./catalina.sh stop vi ../conf/server.xml <Server port=“8005” 8005 -> 8041 <Connector port=“8080” 8080 -> 8042 <Connector port=“8009” 8009 -> 8043

개발환경구축 netstat –antp kill xxxx http://bit.sparcs.org:8042

JSP cd ../webapps/ROOT mv index.jsp _index.jsp vi index.jsp index.jsp <html> <head> </head> <body> Hello, World! </body> <html> <head> </head> <body> <% out.println(new java.util.Date()); %> </body>

JSP Java Server Page 스크립트언어

Context

Servlet cd WEB-INF mkdir classes cd classes vi hello.java import java.io.IOException; import java.io.PrintWriter; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.annotation.WebServlet; @WebServlet(urlPatterns={"/hello"}) public class hello extends HttpServlet{ public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException{ res.setContentType("text/html"); PrintWriter out = res.getWriter(); out.println("<html>"); out.println("<head>"); out.println("</head>"); out.println("<body>"); out.println("Hello, World!"); out.println("</body>"); out.println("</html>"); out.close(); } cd WEB-INF mkdir classes cd classes vi hello.java

Servlet javac –d . hello.java vi ~/.bash_profile CLASSPATH=$CLASSPATH:.:/home/breadfish/struts_tutorial/apache-tomcat-7.0.22/lib/* export CLASSPATH source ~/.bash_profile vi ../web.xml metadata-complete=“true” true -> false restart http://bit.sparcs.org:8042/hello

Web Application Server HTML 웹 어플리케이션 서버(WAS) JS 웹 서버 컨테이너 Class DB .

Web Application Server WAS JVM 서블릿 객체 서블릿 컨테이너 스레드 웹 서버

JSP to Servlet vi ~/struts_tutorial/apache-tomcat-7.0.22/work/Catalina/localhost/_/org/apache/jsp/index_jsp.java

111115 구성모 Struts Tutorial 2

What we are done WAS Container Tomcat JSP Servlet Context

Context

Tomcat catalina… host-manager… localhost… ROOT examples bin lib conf logs catalina… host-manager… localhost… temp work webapps ROOT examples

Create new context cd struts_tutorial mkdir proj1 cd proj1 mkdir WEB-INF mkdir WEB-INF/classes mkdir WEB-INF/lib

Create new context Hello vi tomcat_dir/conf/server.xml vi hello.jsp Just before </Host> <Context path=“proj1” reloadable=“true” docBase=“/home/breadfish/struts_tutorial/proj1” workDir=“/home/breadfish/struts_tutorial/proj1/work”> </Context> vi hello.jsp Hello tomcat restart http://bit.sparcs.org:8042/proj1/hello.jsp

Struts2 action form Web Framework MVC architecture POJO Zero configuration Interceptor Tag Ajax Plug-in

Struts2 install cd ~/struts_tutorial http://apache.mirror.cdnetworks.com//struts/binaries/struts-2.2.3.1-all.zip unzip cd struts-2.2.3/lib copy all jars to [docBase]/WEB-INF/lib

Struts2 Install commons-fileupload-1.2.2.jar commons-logging-api-1.1.jar struts2-convention-plugin-2.2.3.jar commons-lang-2.4.jar ognl-3.0.1.jar struts2-dojo-plugin-2.2.3.jar commons-logging-1.1.1.jar struts2-config-browser-plugin-2.2.3.jar asm freemaker xwork struts2-core

Struts2 intall cd [docBase]/WEB-INF/classes vi StrutsFilter.java javac –d . StrutsFilter.java import javax.servlet.Filter; import javax.servlet.annotation.*; import org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter;   @WebFilter(displayName="Struts2", urlPatterns="/*", filterName="struts2",         initParams={@WebInitParam(name="actionPackages", value="")}) public class StrutsFilter extends StrutsPrepareAndExecuteFilter implements Filter{     private static final long serialVersionUID = 1L; } /[ContextPath]/ 하위로 들어오는 모든 url은 필터디스패처로 들어간다

필터 디스패처 스트러츠2의 컨트롤러 액션을 실행하기 위한 환경을 구축 사용자에게 보낼 응답을 처리

Struts2 Hello, World Hello, World! vi HelloWorldAction.java javac –d . HelloWorldAction.java tomcat restart http://bit.sparcs.org:8042/proj1/hello.action package com.proj1.action import org.apache.struts2.convention.annotation.*; public class HelloWorldAction{      @Action(value="/hello", results={          @Result(name="success", location="/HelloWorld.jsp")})      public String execute(){          return "success";      }  } vi ../../HelloWorld.jsp Hello, World!

Struts2 Annotation 패키지 경로에 action이 들어갈것. struts나 struts2도 된다. Action annotation을 액션 메소드에 붙여주자. Action annotation을 사용하지 않고 class에 Result annotation을 붙여서 액션을 매핑할 수도 있다. 클래스명은 Action으로 끝나야한다.

111122 구성모 Struts Tutorial 3

Struts2 config browser http://bit.sparcs.org:8042/proj1/config-browser/index 현재 매핑되어진 모든 액션과 URL을 확인

Print variable cd [docBase]/WEB-INF/classes vi HelloWorldAction.java package com.proj1.action; import org.apache.struts2.convention.annotation.*; @Namespace("/board") public class HelloWorldAction{ private String message; @Action(value="hello", results={ @Result(name="success", location="/HelloWorld.jsp")}) public String execute(){ message = "I'm breadfish"; return "success"; } public String getMessage(){ return message; public void setMessage(String message){ this.message = message;

Print variable vi ../../HelloWorld.jsp http://bit.sparcs.org:8042/proj1/board/hello Hello, World! <p> ${message}

JSP TAG 종류 사용용도 형식 지시자(Directive) JSP 페이지의 속성 지정 주석(Comment) <%-- --%> 선언(declaration) 변수와 메소드 선언 <%! %> 표현식(expression) 계산식이나 함수를 호출한 결과를 문자열 형태로 출력 <%= %> 스크립트릿(scriptlet) 자바 코드 기술 <% %> 액션 태그 자바 빈이나 애플릿 서버 모듈과 연결 <jsp:action> </jsp:action>

Directive 종류 사용용도 page 해당 JSP 페이지의 속성을 지정 include 현재 페이지에 다른 파일의 내용을 삽입할 때 사용 taglib 태그 라이브러리에서 태그를 꺼내와 사용할 수 있는 기능 제공 <%@ page import=“java.util.Date” %> <%@ page contentType=“text/html; charset=utf-8” %> <%@ include file=“board01.jsp” %>

vi ../../HelloWorld.jsp <%@ page contentType=“text/html; charset=utf-8” %> <%@ taglib prefix=“s” uri=“/struts-tags” %> Hello, World! <p> ${message} <s:property value=“message”></s:property>

print array HelloWorldAction.java package com.proj1.action; import org.apache.struts2.convention.annotation.*; import java.util.List; import java.util.ArrayList; @Namespace("/board") public class HelloWorldAction{ private String message; private List<String> messages; @Action(value="hello", results={ @Result(name="success", location="/HelloWorld.jsp")}) public String execute(){ message = "I'm breadfish"; messages = new ArrayList<String>(); for(int i=0 ; i<10 ; i++){ messages.add("breadfish" + i); } return "success"; public String getMessage(){ return message; } public void setMessage(String message){ this.message = message; public List<String> getMessages(){ return messages; public void setMessages(List<String> messages){ this.messages = messages;

print array HelloWorld.jsp <%@ page contentType="text/html; charset=utf-8" %> <%@ taglib prefix="s" uri="/struts-tags" %> Hello, World! <p> ${message} <s:property value="message"></s:property> <s:iterator value="messages"> <s:property></s:property> </s:iterator>

111129 구성모 Struts Tutorial 4

RESULT … @Action(value="hello", results={ @Result(name="success", location="/HelloWorld.jsp"), @Result(name=“error", type=“dispatcher”, location="/error.jsp")}) public String execute(){ 리절트 타입 설명 Chain 액션 체인을 위하여 사용된다. Dispatcher JSP를 포함안 웹 리소스 연동을 위하여 사용된다. FreeMarker 프리마커 연동을 위하여 사용된다. HttpHeader 특수한 HTTP 작동을 조절하기 위해서 사용 Redirect 다른 URL로 리다이렉트하기 위해 사용 Stream 브라우저에게 inputStream을 스트리밍 하기 위해 사용 PlainText 특수한 페이지(jsp, html 등)의 컨텐츠 원본을 디스플레이 …

form input HelloWorldAction.java compile package com.proj1.action; import org.apache.struts2.convention.annotation.*; import java.util.List; import java.util.ArrayList; @Namespace("/board") public class HelloWorldAction{ private String message; private List<String> messages; @Action(value="hello", results={ @Result(name="success", location="/HelloWorld.jsp")}) public String execute(){ message = "I'm breadfish"; messages = new ArrayList<String>(); for(int i=0 ; i<10 ; i++){ messages.add("breadfish" + i); } return "success"; … compile http://bit.sparcs.org:8042/proj1/board/hello?message=suckstruts

struts-tags : form tag example HelloWorld.jsp HelloWorldAction.java <%@ page contentType="text/html; charset=utf-8" %> <%@ taglib prefix="s" uri="/struts-tags" %> <%@ taglib prefix="sx" uri="/struts-dojo-tags" %> <html> <head> <sx:head/> </head> <body> <form action="" method="GET"> <sx:datetimepicker name="sdate"/> <input type="submit"/> </form> ${sdate} </body> </html> package com.proj1.action; import org.apache.struts2.convention.annotation.*; import java.util.List; import java.util.ArrayList; import java.util.Date; @Namespace("/board") public class HelloWorldAction{ private Date sdate; @Action(value="hello", results={ @Result(name="success", location="/HelloWorld.jsp")}) public String execute(){ return "success"; } public Date getSdate(){ return sdate; public void setSdate(Date sdate){ this.sdate = sdate;

struts-tags : control tag example HelloWorld.jsp <%@ page contentType="text/html; charset=utf-8" %> <%@ taglib prefix="s" uri="/struts-tags" %> <%@ taglib prefix="sx" uri="/struts-dojo-tags" %> <html> <head> <sx:head/> </head> <body> <s:if test="%{message=='show'}"> <sx:textarea></sx:textarea> </s:if> <s:else> Message : ${message} </s:else> </body> </html>

Tags Control Tags if elseif else append generator iterator merge sort subset Data Tags a action bean date debug i18n include param property push set text url

Tags Form Tags checkbox checkboxlist combobox doubleselect head file hidden inputtransferselect label optiontransferselect optgroup password radio reset select submit textarea textfield token updownselect Ajax Tags a autocompleter bind datetimepicker div tabbedPanel tree treenode

More - JSP Script Action Tag Cookie Session request, response Exception handler Bean OGNL FILE

More - Struts Interceptor Action mapper Annotation Ajax Logging

More DAO, VO FreeMaker SiteMesh Tiles mybatis hibernate Model Template ORM mybatis hibernate

References 스트럿츠2 프로그래밍, 현철주 외 3명, 에이콘 초보 개발자를 위한 서블릿 JSP 프로그래밍, 성윤광 외 3명, 대림 http://struts.apache.org/2.x

Thanks Q&A 톰캣로그, /hello보는법, 서블릿의뜻