struts2基本配置

struts.xml 放在src目录下
<?xml version="1.0" encoding="UTF-8"?>
<struts>
<package name="struts2 " namespace="/" extends="struts-default">
<action name="sum" class="com.umgsai.test.FirstAction">
<result name="positive ">/positive.jsp</result>
<result name="negative ">/negative.jsp</result>
</action>
</package>
</struts>
web.xml中添加配置
<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>
lib目录下添加jar包
asm-x.x.jar
asm-commons-x.x.jar
asm-tree-x.x.jar
commons-io-X.X.X.jar
commons-lang3-X.X.X.jar
commons-fileupload-X.X.X.jar
freemarker-X.X.X.jar
javassist-X.X.X.jar
ognl-X.X.X.jar
struts2-core-X.X.X.X.jar
xwork-core-X.X.X.jar

java文件
package com.umgsai.test;
import com.opensymphony.xwork2.ActionSupport;
publicclass FirstAction extends ActionSupport {
/**
*
*/
privatestaticfinallong serialVersionUID = 1L;
privateint operand1;
privateint operand2;
public String execute() throws Exception {
if (getSum() >= 0) // 如果代码数和是非负整数,跳到positive.jsp页面
{
return"positive";
} else// 如果代码数和是负整数,跳到negative.jsp页面
{
return"negative";
}
}
publicint getOperand1() {
return operand1;
}
publicvoid setOperand1(int operand1) {
System.out.println(operand1);
this.operand1 = operand1;
}
publicint getOperand2() {
return operand2;
}
publicvoid setOperand2(int operand2) {
System.out.println(operand2);
this.operand2 = operand2;
}
publicint getSum() {
return operand1 + operand2; // 计算两个整数的代码数和
}
}
sum.jsp文件
<%@ page language="java"import="java.util.*"pageEncoding="GBK"%>
<%@ taglib prefix="s"uri="/struts-tags"%>
<%
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>
<basehref="<%=basePath%>">
<title>输入操作数</title>
<metahttp-equiv="pragma"content="no-cache">
<metahttp-equiv="cache-control"content="no-cache">
<metahttp-equiv="expires"content="0">
<metahttp-equiv="keywords"content="keyword1,keyword2,keyword3">
<metahttp-equiv="description"content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body>
求代数和
<br/>
<s:formaction="sum"namespace="/">
<s:textfieldname="operand1"label=" 操作数1"/>
<s:textfieldname="operand2"label=" 操作数2"/>
<s:submitvalue="代数和"/>
</s:form>
</body>
</html>
positive.jsp页面
<%@ page language="java"import="java.util.*"pageEncoding="GBK"%>
<%@ taglib prefix="s"uri="/struts-tags"%>
<%
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>
<basehref="<%=basePath%>">
<title>显示代数和</title>
<metahttp-equiv="pragma"content="no-cache">
<metahttp-equiv="cache-control"content="no-cache">
<metahttp-equiv="expires"content="0">
<metahttp-equiv="keywords"content="keyword1,keyword2,keyword3">
<metahttp-equiv="description"content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body>
代数和为非负整数
<h1>
<s:propertyvalue="sum"/>
</h1>
</body>
</html>
negative.jsp页面
<%@ page language="java"import="java.util.*"pageEncoding="GBK"%>
<%@ taglib prefix="s"uri="/struts-tags"%>
<%
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>
<basehref="<%=basePath%>">
<title>显示代数和</title>
<metahttp-equiv="pragma"content="no-cache">
<metahttp-equiv="cache-control"content="no-cache">
<metahttp-equiv="expires"content="0">
<metahttp-equiv="keywords"content="keyword1,keyword2,keyword3">
<metahttp-equiv="description"content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body>
代数和为负整数
<h1>
<s:propertyvalue="sum"/>
</h1>
</body>
</html>
------------------------------------------------------------------------------
struts2基本配置的更多相关文章
- Struts2 基本配置
Struts2是一个优秀的MVC框架,也是我比较喜欢用的框架.它个各种配置基本都可以集中在一个xml文档中完成.现在让我们看看如何简单几步实现常用功能. 一.搭建Struts2的开发环境 1)首先是利 ...
- Struts2 XML配置详解
struts官网下载地址:http://struts.apache.org/ 1. 深入Struts2的配置文件 本部分主要介绍struts.xml的常用配置. 1.1. 包配置: S ...
- struts2 action配置时 method 省略不写 默认执行方法是父类ActionSuppot中的execute()方法
struts2 action配置时 method 省略不写 默认执行方法是父类ActionSuppot中的execute()方法
- struts2环境配置
struts2环境配置 struts2框架,大多数框架都在使用.由于工作需要,开始做Java项目.先学个struts2. 一.下载struts2 有好多版本,我下载的是struts-2.2.1.1. ...
- 在Struts2中配置Action
在Struts2中配置Action <package>: 1.定义Action使用<package>标签下的<action>标签完成,一个<package&g ...
- Struts2的配置
Struts2的配置 Struts2可以通过Convention插件管理Action和结果映射,也可以通过使用XML文件进行管理,这两种方式各有好处:使用Convention插件管理减少了XML文件的 ...
- Struts2的配置和一个简单的例子
Struts2的配置和一个简单的例子 笔记仓库:https://github.com/nnngu/LearningNotes 简介 这篇文章主要讲如何在 IntelliJ IDEA 中使用 Strut ...
- 1-1 struts2 基本配置 struts.xml配置文件详解
详见http://www.cnblogs.com/dooor/p/5323716.html 一. struts2工作原理(网友总结,千遍一律) 1 客户端初始化一个指向Servlet容器(例如Tomc ...
- spring+hibernate+struts2零配置整合
说句实话,很久都没使用SSH开发项目了,但是出于各种原因,再次记录一下整合方式,纯注解零配置. 一.前期准备工作 gradle配置文件: group 'com.bdqn.lyrk.ssh.study' ...
- struts2基本配置详解2
接上篇struts2基本配置详解,还有一些配置没有讲到,下面将继续. struts.xml <package name="com.amos.web.action" names ...
随机推荐
- 数据库SQL优化大总结之 百万级数据库优化方案(转)
1.对查询进行优化,要尽量避免全表扫描,首先应考虑在 where 及 order by 涉及的列上建立索引. 2.应尽量避免在 where 子句中对字段进行 null 值判断,否则将导致引擎放弃使用索 ...
- 找不到类型{0} 它在 ServiceHost 指令中提供为 Service 特性值
由于我把binding改成wsHttpBinding,在web.config里也改了命名空间 services的类名也改成了跟 web.config对应的命名空间后 在添加引用后,出现了错误: “找不 ...
- ZooKeeper学习第六期---ZooKeeper机制架构
一.ZooKeeper权限管理机制 1.1 权限管理ACL(Access Control List) ZooKeeper 的权限管理亦即ACL 控制功能,使用ACL来对Znode进行访问控制.ACL的 ...
- OpenShift
一步一脚印 停停走走,回头看看 博客园 首页 新随笔 联系 订阅 管理 随笔 - 24 文章 - 8 评论 - 2 调戏OpenShift:一个免费能干的云平台 一.前因后果 以前为了搞微信的 ...
- C语言操作符优先级
C语言操作符优先级 优先级 运算符 含 义 要求运算 对象的个数 结合方向 1 () [] -> . 圆括号 下标运算符 指向结构体成员运算符 结构体成员运算符 自左至右 2 ! 逻辑非运 ...
- [CareerCup] 4.6 Find Next Node in a BST 寻找二叉搜索树中下一个节点
4.6 Write an algorithm to find the'next'node (i.e., in-order successor) of a given node in a binary ...
- .NET MVC框架中控制器接收参数的四种方式
1.通过路由中的配置的参数名字直接接收(要求:两者同名) routes.MapRoute( name: "Default", ...
- [网站公告]23:00-05:00阿里云SLB升级会造成4-8次每次10秒的闪断
大家好,阿里云将于今天夜里(7月29日23:00-7月30日05:00)对负载均衡服务(SLB)进行升级操作,升级期间我们使用的SLB实例会有4-8次的闪断,每次闪断时间10秒左右.闪断期间会造成网站 ...
- struts1日期转换处理
问题场景 最近在维护公司旧的系统(用的struts1框架)的时候,在日期处理的时候,我将日期设定为Date类型,结果报以下错误: javax.servlet.ServletException: Bea ...
- eclipse快捷键的使用及概述
<eclipse快捷键的使用及概述> <Eclipse概述> Eclipse 是一个开放源代码的.基于Java的可扩展开发平台.就其本身而言,它只是一个框架和一组服 ...