首先我们先导入一些基本的包:
asm-3.3.jar :操作java字节码的类库;(反射的替代方案,ASM是小巧轻便的 Java 字节码操控框架 ,它能方便地动态生成和改造 Java 代码。)
asm-commons-3.3.jar :提供了基于事件的表现形式;
asm-tree-3.3.jar :提供了基于对象的表现形式;
commons-fileupload-1.3.jar :struts文件的上传与下载;
commons-io-2.0.1.jar :可以看成是java.io的扩展;
commons-lang3-3.1.jar :为java.lang包提供扩展;
commons-logging-1.1.3.jar :Jakarta的通用日志记录包;
freemarker-2.3.19.jar :FreeMarker是一个模版引擎,一个基于模版生成文本输出的通用工具;
javassist-3.11.0.GA.jar :javassist是用来操作字节码的;
ognl-3.0.6.jar :一种功能强大的表达语言;
struts2-convention-plugin-2.3.15.3.jar :注解用的包;
struts2-core-2.3.15.3.jar :struts的核心包;
xwork-core-2.3.15.3.jar :webwork 的核心包;(struts2是由webwork发展而来的)
<filter> <filter-name>struts2</filter-name> <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class> </filter> <filter-mapping> <filter-name>struts2</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>
package com.po;
public class Hello {
private String name;
public String say(){
this.name = "xiao‘er";
return "success";
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
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>sfd</title> </head> <body> ${name } </body> </html>
struts.xml
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN" "http://struts.apache.org/dtds/struts-2.3.dtd"> <struts> <package name="mypk" extends="struts-default"> <action name="hello" class="com.po.Hello" method="say"> <result name="success">index.jsp</result> </action> </package> </struts>
效果:
Struts(1) 一个hello的struts,布布扣,bubuko.com