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 ...
随机推荐
- C#把某个数组的一部分复制到另一个数组中的两种方法:Buffer.BlockCopy和Array.Copy
static void Main(string[] args) { , , , , , }; ;//目标数组大小 int int_size = sizeof(int);//用于获取值类型的字节大小. ...
- [iOS翻译]《iOS7 by Tutorials》系列:iOS7的设计精髓(下)
我们继续上篇的内容 四.聚焦于内容 在iOS7里,强调的不是眼花缭乱的装饰效果,而是最重要的内容本身. 下面我们来探讨这个主题: 1.删除不必要的内容 伟大的设计更多是减法和加法的组合. 虽然很酷的想 ...
- sqlalchemy 的 raw sql 方式使用示例
#获取数据库 from sqlalchemy import create_engine db = create_engine("sqlite:///:memory:", echo= ...
- vbs实现的支持拖动的txt文本切割器
vbs实现的支持拖动的txt文本切割器 作者: 字体:[增加 减小] 类型:转载 时间:2008-06-20我要评论 用vbs实现的txt文本文件切割器,默认为8000个字符切为一个文件.支持拖动. ...
- ios 指南针
指南针图片 IBOutlet UIImageView *compassView 1 #import "ViewController.h" #import <CoreLoca ...
- poj1067-取石子游戏-wythoff博弈
打表找规律失败,搜了一下原来是wythoff博弈 /*------------------------------------------------------------------------- ...
- silverlight ListBox 多列图片效果
这个功能之前用wpf写过一次这次用Silverlight写一次 这两种写法上基本上没有太大的差别 这个Demo并不完美,只是给大家提供一个思路 源码:SilverLightListPricture.r ...
- HoloLens开发手记 - Unity之Persistence 场景保持
Persistence 场景保持是HoloLens全息体验的一个关键特性,当用户离开原场景中时,原场景中全息对象会保持在特定位置,当用户回到原场景时,能够准确还原原场景的全息内容.WorldAncho ...
- WINDOWS8.1安装ORACLE客户端及配置
1.官方网站下载: instantclient-basic-win32-11.2.0.1.0.zip instantclient-sqlplus-win32-11.2.0.1.0.zip instan ...
- QRadioButton分组且无边框的简单实现
最近在用QT+VS2008做一个项目,涉及到一个综合测评表,说白了有点像问卷调查——很多题目每题若干个选项. 初始时打算用下拉框,每个框中填入所有选项,但后来一琢磨这种方式不够直观与人性化,增添了一步 ...