Required jar:
commons-fileupload-1.2.X.jar
commons-logging-1.0.X.jar
freemarker-2.3.X.jar
ognl-2.1.X.jar
struts2-convention-plugin-2.1.X.jar
struts2-core-2.1.6.jar
xwork-2.1.2.jar
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>Struts2Tutorial</display-name>
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
<init-param>
<param-name>actionPackages</param-name>
<param-value> com.qtec.struts2</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
</web-app>
index.jsp
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<!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>Index Jsp</title>
</head>
<body>
<s:form action="helloWorld" theme="simple">
<s:textfield name="username"/><s:fielderror fieldName="username"/>
<s:submit value="Greetting"/>
</s:form>
</body>
</html>
greetting.jsp
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<!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>Index Jsp</title>
</head>
<body>
<h3>Hello,</h3>
<s:property value="username"/>
</body>
</html>
HelloWorld.java
package com.qtec.struts2.day1;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.validator.annotations.RequiredStringValidator;
import com.opensymphony.xwork2.validator.annotations.StringLengthFieldValidator;
import com.opensymphony.xwork2.validator.annotations.Validations;
/**
*
* @author Bill.Zhang
*
*/
@ParentPackage("struts-default")
@Namespace("/")
@Validations
public class HelloWorldAction extends ActionSupport {
/**
*
*/
private static final long serialVersionUID = 1L;
@Action(value="helloWorld",
results={
@Result(name="success",location="/greetting.jsp"),
@Result(name="input",location="/index.jsp")
}
)
/* @Validations(
requiredStrings={@RequiredStringValidator(message="Supply username",fieldName="username")}
)*/
public String execute() throws Exception {
return SUCCESS;
}
private String username;
public String getUsername() {
return username;
}
@RequiredStringValidator(message="Supply username",fieldName="username")
@StringLengthFieldValidator(minLength="2",maxLength="12",message="username minLength is ${minLength}, maxLength is ${maxLength}")
public void setUsername(String username) {
this.username = username;
}
}
分享到:
相关推荐
- **Validation**:标记一个类需要被校验,通常配合Struts的配置文件使用。 ### 验证器类型详解 1. **ConversionErrorFieldValidator**:用于检测字段转换时是否出现错误,例如将字符串转换为日期时的异常情况。 2...
2. Annotation配置:通过在Action类上使用注解,可以简化XML配置,提高开发效率。 三、Struts2 Action与结果 1. Action类:实现Action接口或继承ActionSupport基类,定义execute()方法处理请求。 2. Result类型:...
scratch少儿编程逻辑思维游戏源码-米克 demo.zip
scratch少儿编程逻辑思维游戏源码-萝卜男孩拯救世界.zip
scratch少儿编程逻辑思维游戏源码-酷忍者.zip
教育科技_微信小程序_二手交易平台_大学校园二手书与物品循环利用公益系统_风华读书人校园二手交易平台_基于C2C模式的校内闲置物品交易系统_支持多校区独立运营的二手书交易平台_包含
全新UI彩虹外链网盘系统源码前后端美化模板整站 模版文件.zip
maoxig_nonebot-plugin-ai-timetable_32152_1745865455265
少儿编程scratch项目源代码文件案例素材-足球顶尖高手.zip
少儿编程scratch项目源代码文件案例素材-作战基地.zip
少儿编程scratch项目源代码文件案例素材-云端之上 1-4名玩家.zip
scratch少儿编程逻辑思维游戏源码-魔幻之塔.zip
scratch少儿编程逻辑思维游戏源码-楼层酷跑.zip
scratch少儿编程逻辑思维游戏源码-圈.zip
少儿编程scratch项目源代码文件案例素材-纸片马里奥自定义战役.zip
少儿编程scratch项目源代码文件案例素材-自由下落.zip
少儿编程scratch项目源代码文件案例素材-阻击蜈蚣.zip
健康监测与疾病预防_脉搏波分析_六轴加速度传感器_生理参数融合_STC12硬件采集_Android数据处理_SpringBoot后端_MySQL数据库_MatlabPython实验
音乐流媒体应用开发_基于JetpackCompose的跨平台开发_网易云音乐风格的多终端音乐播放器_包含手机平板电视手表四端适配的现代化音乐播放应用实现音乐发现播放列表管理个性化推
移动应用开发_Android_Kotlin_Jetpack_开源框架_课程表应用_学生管理_教育信息化_云舒课表_智能课表_课表提醒_成绩查询_主题定制_背景更换_自动静音_校园生