1>web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
id="WebApp_ID" version="3.1">
<display-name>Test</display-name>
<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>
<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>
</web-app>

2>userAction.java

package com.Test.action;

public class UserAction {
String info; public String getInfo() {
return info;
} public void setInfo(String info) {
this.info = info;
} public String find() {
if (info.endsWith(".vip")) {
return "vip";
}
return "regular";
}
}

3>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>
<!-- 动态方法调用 -->
<constant name="struts.enable.DynamicMethodInvocation" value="true" />
<package name="helloPackage" extends="struts-default">
<action name="userAction" class="com.Test.action.UserAction" method="find">
<result name="vip">/vip.jsp</result>
<result name="regular">/nvip.jsp</result>
</action>
</package>
</struts>

4>index.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>Insert title here</title>
</head>
<body>
<form action="userAction">
<table border="1" width="400px" height="200px">
<tr>
<td>请输入用户名:</td>
<td><input name="info" type="text" /></td>
</tr>
<tr>
<td colspan="2"><input type="submit" name="submit" value="提交" /></td>
</tr>
</table>
</form>
</body>
</html>

5>相关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>Insert title here</title>
</head>
<body>
<h1>VIP</h1>
<s:property value="info" />
</body>
</html>

vip.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>Insert title here</title>
</head>
<body>
<h1>NOT VIP ,HELLOWORLD</h1>
<s:property value="info" />
</body>
</html>

nvip.jsp

注意:1>在form表单中,action值为struts.xml中的action中的name值,习惯上在后面再写个.action,不写也没关系,

   2>在input中,name值要与action.java中的属性名称一致,

2016/10/29 action与form表单的结合使用的更多相关文章

  1. struts2总结四:Action与Form表单的交互

    struts2 Action获取表单数据的方式有三种:1.通过属性驱动的方式.2.模型驱动方式.3.使用多个model对象的属性. 1.通过属性驱动式 首先在jsp里面编写form表单的代码如下: & ...

  2. 2016/10/29 Action类中execute方法的使用

    第一步:先配置web.xml文件 <filter> <filter-name>struts2</filter-name> <filter-class>o ...

  3. 通过button将form表单的数据提交到action层

    form表单中不需要写action的路径,需要给form表单一个唯一的id,将你要提交的信息的表单中的标签name="action中的javabean对象.javabean属性". ...

  4. form表单提交路径action="" 时的一种特殊情况

    一.说明: 当页面的form表达的action=""时,表示表单会提交到当前页面,但是如果当前页面的URL里已经带有一个参数了,每次提交表达时这个参数依然存在,不管form表单里有 ...

  5. Liferay7 BPM门户开发之40: Form表单的Action到Render的数据传递

    在Form提交后的变量,很多情况是要展现在jsp页面中,这时Action到Render的变量传递就非常有用. 例如,您在数据库中添加了学生的详细信息. 为了实现这一需求,先创建Form表单(学生的细节 ...

  6. Form表单中的action路径问题,form表单action路径《jsp--->Servlet路劲问题》这个和上一个《jsp--->Servlet》文章有关

    Form表单中的action路径问题,form表单action路径 热度5 评论 50 www.BkJia.Com  网友分享于:  2014-08-14 08:08:01     浏览数44525次 ...

  7. Js document.frmLogin.action = '/login.htm';的意义和form表单的target属性

    一.解答:就是把 这个id名为frmLogin的form的提交地址改为上面的/login.htm <form id="frmLogin" name="frmLogi ...

  8. form 表单 action 参数 接收不了

    <form method="get" action="/test/index.php?mod=123456" > <input type=&q ...

  9. asp.net使用post方式action到另一个页面,在另一个页面接受form表单的值!(报错,已解决!)

    原文:asp.net使用post方式action到另一个页面,在另一个页面接受form表单的值!(报错,已解决!) 我想用post的方式把一个页面表单的值,传到另一个页面.当我点击Default.as ...

随机推荐

  1. VB和VB.NET有什么区别

    作为VB6.0的后续版本,VB.NET更加稳定,而且完全面向对象.也许你还记得,VB6.0部支持继承.重载和接口,所以不是真正面向对象的.而VB.NET则支持这些面向对象特性.VB6.0有两个薄弱环节 ...

  2. ASP.NET Web Pages - 教程

    ASP.NET Web Pages - 教程 ASP.NET 是一个使用 HTML.CSS.JavaScript 和服务器脚本创建网页和网站的开发框架. ASP.NET 支持三种不同的开发模式:Web ...

  3. Dropbox电面面经

    他家电面有2轮,等待onsite.. . 电面1: 国人MM面的.这点感觉非常难得. 统计近期5分钟的点击量,实现hit和getHit两个函数.这题是他家高频题,我用deque实现的,hit的均摊时间 ...

  4. soapUI系列之—-06 testrunner实现自动化测试

    TestRunner为soapUI自带------testrunner.bat/testrunner.sh 实现步骤: 1. 使用soapUI,针对接口文件创建测试用例. 2. 将测试用例保存至本地, ...

  5. Android学习 多读官网,故意健康---手势

    官网地址 ttp://developer.android.com/training/gestures/detector.html: 一.能够直接覆盖Activity的onTouch方法 public ...

  6. STL_算法_最小值和最大值(min_element、max_element)

    C++ Primer 学习中... 简单记录下我的学习过程 (代码为主) min_element.max_element  找最小.最大值. 非常easy没什么大作用 #include<iost ...

  7. JAVA设计模式(01):创建型-工厂模式【工厂方法模式】(Factory Method)

    简单工厂模式尽管简单,但存在一个非常严重的问题.当系统中须要引入新产品时,因为静态工厂方法通过所传入參数的不同来创建不同的产品,这必然要改动工厂类的源码,将违背"开闭原则".怎样实 ...

  8. ArrayAdapter requires the resource ID to be a TextView

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAABDUAAADFCAIAAADLz168AAAgAElEQVR4nO2d368kxZXnQ37dn9qdWa

  9. 不等式数列 DP

    度度熊最近对全排列特别感兴趣,对于1到n的一个排列,度度熊发现可以在中间根据大小关系插入合适的大于和小于符号(即 '>' 和 '<' )使其成为一个合法的不等式数列.但是现在度度熊手中只有 ...

  10. SprigMVC基础测试

    创建POJO package org.entity; public class User { private int id; private String userName; private Stri ...