struts2开发流程及详细配置

网友投稿 236 2023-03-31


struts2开发流程及详细配置

一:Struts开发步骤:

1. web项目,引入struts - jar包

2. web.xml中,引入struts的核心功能

配置过滤器

3. 开发action

4. 配置action

src/struts.xml

二:详细配置

1.引入8个jar文件

commons-fileupload-1.2.2.jar   【文件上传相关包】

commons-io-2.0.1.jar

struts2-core-2.3.4.1.jar           【struts2核心功能包】

xwork-core-2.3.4.1.jar           【Xwork核心包】

ognl-3.0.5.jar      【Ognl表达式功能支持表】

commons-lang3-3.1.jar          【struts对java.lang包的扩展】

freemarker-2.3.19.jar            【struts的标签模板库jar文件】

javassist-3.11.0.GA.jar           【struts对字节码的处理相关jar】

2.web.xml详细配置

&lhttp://t;?xml version="1.0" encoding="UTF-8"?>

    xmlns:xsi="http://w3.org/2001/XMLSchema-instance"

    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee

    http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">

    

    

    

        struts2

        org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter

    

    

        struts2

        /*

    

    

        index.jsp

    

    xmlns:xsi="http://w3.org/2001/XMLSchema-instance"

    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee

    http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">

    

    

    

        struts2

        org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter

    

    

        struts2

        /*

    

    

        index.jsp

    

3.开发Action(3种方式)

1种:直接继承ActionSupport

package cn.itcast.a_config;

import com.opensymphony.xwork2.ActionSupport;

public class UserAction extends ActionSupport {

// Action中业务处理方法

public String login() {

System.out.println("UserAction.login()");

return "success";

}

}

2种:继承Action接口

package cn.itcast.a_config;

import com.opensymphony.xwork2.Action;

import com.opensymphony.xwork2.ActionSupport;

public class UserAction implements Action {

// Action中业务处理方法

public String login() {

System.out.println("UserAction.login()");

return "success";

}

@Override

public String execute() throws Exception {

return null;

}

}

3种:不继承任何类,http://不实现任何接口

package cn.itcast.a_config;

import com.opensymphony.xwork2.Action;

import com.opensymphony.xwork2.ActionSupport;

public class UserAction {

private String userName;

public void setUserName(String userName) {

this.userName = userName;

}

// Action中业务处理方法

public String login() {

System.out.println("UserAction.login()" + userName);

return "login";

}

public String register() {

System.out.println("register()" + userName);

return "register";

}

}

4. 配置action :  src/struts.xml

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

    "http://struts.apache.org/dtds/struts-2.3.dtd">

    

    

            /index.jsp

    

    

本文有关struts开发流程及详细配置的内容就到这里,希望对大家有所帮助。有兴趣的朋友可以参阅:struts1之简单mvc示例_动力节点Java学院整理、jsp 开发之struts2中s:select标签的使用等。欢迎阅读本站其他有关专题,感谢大家对我们的支持!


版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:Java中迭代器Iterator的使用解析
下一篇:接口测试用例的设计思路(接口测试用例的设计思路或方法)
相关文章

 发表评论

暂时没有评论,来抢沙发吧~