1. Trang chủ
  2. » Công Nghệ Thông Tin

Java C13. Struts pptx

66 399 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 66
Dung lượng 1,84 MB

Nội dung

struts- Execute the authentication processing by calling a corresponding Action class LoginAction.. Making JSP file for displayHtml tag library Tag that execute Struts own execution Bea

Trang 1

Chapter 13 StrutsITSS Java Programming Ngo Hong Son, HUT

Trang 3

Processing of screen control framework

Response

Trang 4

Typical screen control framework

Process(JCP)

Trang 5

When framework is not used (1)

Trang 6

public class ControllerServlet extends HttpServlet {

protected void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException { try {

}

}

When framework is not used (2)

1 Acquire the request parameter

2 Decide transition destination’s screen according to request parameter

3 Transfer to the transition destination‘s screen

Trang 7

When framework is used

Trang 8

Struts description

using Servlet and JSP

storage of data, screen transition control, etc

file (struts-config.xml)

Trang 9

 Change the language displayed on the client side

by the browser's language setting

Trang 10

Struts components

Trang 11

ActionServlet class

the form class and the action class

corresponding to the request

Trang 12

Configuration file (struts-config.xml)

according to the request

the object screen of processing result.

Trang 13

Form Bean (Action form class)

form and the link

Trang 14

JSP file for display

JSP, and Struts.

Trang 15

Action class

the Struts

call the method.

Trang 16

Operation principle of Struts (1)

Trang 17

Operation principle of Struts (2)

 Screen (loginForm.jsp) is displayed to the client

 Login: the ActionServlet will be called

 ActionServlet refers the configuration file config.xml)

(struts- Execute the authentication processing by calling a corresponding Action class (LoginAction)

 Decides the JSP of the transition destination,

according to the result authenticated

 The ActionServlet refers to the configuration file, and selects the transition destination's JSP

 Returns the client the screen of the processing

result

Trang 18

Making class based on framework

Trang 19

Procedure of Struts application

Trang 20

Registration to struts-config.xml

<?xml version="1.0" encoding="Shift_JIS"?>

<!DOCTYPE struts-config PUBLIC

"-//Apache Software Foundation//DTD Struts Configuration 1.2//EN"

<forward name="success" path="/jsp/loginSuccess.jsp" />

<forward name="error" path="/jsp/loginError.jsp" />

Trang 21

Definition of form Bean class

Trang 22

Definition of Action class

Trang 23

Making JSP file for display

Html tag library Tag that execute Struts own execution

Bean tag library Tag that acquire and display Bean property and

variable

Logic tag library Tag that execute processing such as repetition

or branching

TLD file Xml form file that defines use of custom tag, in

struts, struts-html.tld and struts-bean.tld and

so on are prepared

Trang 24

Login sample program

Trang 25

Outline

Trang 26

Hello Struts

Trang 27

Select [File] – [New] – [Project]

Trang 28

Hello Struts

Select [Tomcat project] in [New project] window, and click on [Next] buttonName project blank ->

Finish

Trang 29

Libraries to import

Find them in the lib directory of Struts-2

package

Trang 30

How to import jars?

Trang 31

Hello Struts

Import or edit files:

struts.xmlweb.xmlHelloWorld.javaHelloWorld.jsp

Find them on tutorial pages of struts 2 packages

Trang 32

struts.xml

Trang 33

web.xml

Trang 34

HelloWorld.java

Trang 35

HelloWorld.jsp

Trang 36

You got it!

Trang 37

How it works?

Trang 38

Login example

Trang 39

Sample program for Struts login processing

Select [File] – [New] – [Project]

Trang 40

Sample program for Struts login processing

Select [Tomcat project] in [New project] window, and click on [Next] button

Trang 41

Sample program for Struts login processing

Give the following project name in [New Tomcat project] window,

and click the [Finish] button Project name: LoginExample

Trang 42

Sample program for Struts login processing

Confirm that the “LoginExample” project is

created in the “Package Explorer” view

Trang 43

Sample program for Struts login processing

Right-click [LoginExample project],

and select [Import]

Trang 44

Sample program for Struts login processing

Select [File System] on [Import] screen,

and click on [Next] button

Trang 46

Sample program for Struts login processing

Click on [Tomcat run] button

Start Tomcat Stop Tomcat Restart Tomcat

Trang 47

Sample program for Struts login processing

Verify with the "Console" view that Tomcat

is started

Trang 48

Run it now

Trang 49

How it work

Logon.jsp

(1)

Action Servlet

Success.jsp Logon.jsp

Trang 50

<package name="tutorial" extends="struts-default">

<action name="Logon" class="tutorial.Logon">

<result name="input"> /Logon.jsp</result>

<result type="redirectAction">Success </result>

Trang 52

<html>

<head><title>Dang nhap thanh cong</title></head>

<body>

<h3> Chuc mung ban da thanh cong </h3>

<a href="Logon"> Quay tro lai trang ban dau </a>

</body>

</html>

Trang 53

Logon.java (1)

package tutorial;

import com.opensymphony.xwork2.ActionSupport; public class Logon extends ActionSupport {

public String execute() throws Exception {

if (isInvalid(getUsername())) return INPUT;

if (isInvalid(getPassword())) return INPUT;

Trang 54

Logon.java (2)

private String username;

public String getUsername() {

private String password;

public String getPassword() {

Trang 55

Validator functions

Trang 56

User doing validation

Trang 57

Struts does it for you

Input to be

validated Defined by struts

Validation registration by

xml files

Trang 58

Client-side validation

Trang 59

Basic steps for validation

Create the form

Create the Action class

Create the validation.xml

Trang 60

Example: Step 1

Trang 63

Results

Trang 64

Tips: To avoid validation fire at the beginning

<struts>

<package name="" extends="struts-default">

<action name="Basic_*" method="{1}" class="QuizAction">

Trang 65

Hand-on exercices

defined by students)

Trang 66

Hand-on exercises

Ngày đăng: 28/06/2014, 03:20

TỪ KHÓA LIÊN QUAN

w