struts-2.5.14.1-all.zip  下载后文件夹说明

apps:war格式的例子文件

lib:引用jar包文件

src:源码文件

docs:帮助文档

小例子:

1.创建web工程:struts

 <?xml version="1.0" encoding="UTF-8"?>
<web-app id="starter" 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"> <!-- START SNIPPET: filter -->
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<!-- START SNIPPET: filter --> <filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping> <!-- Welcome file lists -->
<welcome-file-list>
<welcome-file>login.jsp</welcome-file>
</welcome-file-list>
</web-app>

WEB.xml

2.页面文件 login.jsp

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>"> <title>My JSP 'login.jsp' starting page</title> <meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
--> </head> <body> <form action="login.action"> username: <input type="text" name="username"><br>
password: <input type="password" name="password"><br>
age: <input type="text" name="age"><br>
date: <input type="text" name="date"><br> <input type="submit" value="submit"> </form> </body>
</html>

login.jsp

3.Struts配置文件(struts.xml默认是在src文件夹下)

 <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.5//EN"
"http://struts.apache.org/dtds/struts-2.5.dtd">
<struts> <package name="struts2" extends="struts-default">
<action name="login" class="com.shengsiyuan.struts2.LoginAction">
<result name="success">/result.jsp</result>
</action>
</package> </struts>

struts.xml

4.调用文件

 package com.shengsiyuan.struts2;

 import java.util.Date;

 public class LoginAction
{
private String username; private String password; private int age; private Date date; public Date getDate()
{
return date;
} public void setDate(Date date)
{
this.date = date;
} public int getAge()
{
return age;
} public void setAge(int age)
{
this.age = age;
} public String getUsername()
{
return username;
} public void setUsername(String username)
{
this.username = username;
} public String getPassword()
{
return password;
} public void setPassword(String password)
{
this.password = password;
} public String execute()
{
return "success";
}
}

LoginAction

5.返回请求响应页

 <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>"> <title>My JSP 'result.jsp' starting page</title> <meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
--> </head> <body> username: ${requestScope.username }<br>
password: ${requestScope.password }<br>
age: ${requestScope.age }<br>
date: ${requestScope.date }
</body>
</html>

result.jsp

代码结构

引用jar文件:struts-2.5.14.1-all.zip 文件中内容

额外注意:需要xwork-core-2.2.1.1.jar(不能上传文件)

http://localhost:8080/struts2/login.jsp 访问地址

最新文章

  1. Node6.9.2 —— Http官网笔记整理
  2. Kudu 实时的存储系统
  3. PLSQL往表中插入中文乱码解决办法
  4. 【翻译习作】 Windows Workflow Foundation程序开发-第一章01
  5. 【现代程序设计】【homework-07】
  6. HDU1429+bfs+状态压缩
  7. gulp 构建工具
  8. 国内好用的公用DNS 服务器。
  9. rgbdslam_v2安装并使用
  10. Access denied for user ‘root’@‘localhost’(using password: YES)的解决方法
  11. 修改AD FS
  12. [置顶]ABP框架系列总目录(持续更新)
  13. base operand of &#39;-&gt;&#39; has non-pointer type &#39;const Comple
  14. 【托业】【新东方全真模拟】01~02-----P5~6
  15. iOS开发小技巧 - runtime适配字体
  16. 微信小程序——修改data里面数组某一个值
  17. CentOS7安装OpenStack(Rocky版)-09.安装Cinder存储服务组件(控制节点)
  18. Redis:Redis
  19. 浅析NSTextContainer
  20. 【elaseticsearch】elaseticsearch启动报错Caused by: org.elasticsearch.transport.BindTransportException: Failed to bind to [9300-9400]

热门文章

  1. PocketBeagle 初高级设置
  2. vue install 注册组件
  3. binary-tree-zigzag-level-order-traversal——二叉树分层输出
  4. oracle 客户端连接
  5. Oracle 字段类型
  6. WinForm搭载ScintillaNET时文本由于发生偏移被隐藏解决方案
  7. 阿里云官方教程 Linux 系统挂载数据盘
  8. 【Union Find】JAVA implementation
  9. easyui datagrid自己定义操作列
  10. HDU1845Jimmy’s Assignment(无向图,最大匹配)