2016/10/29 action与form表单的结合使用
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表单的结合使用的更多相关文章
- struts2总结四:Action与Form表单的交互
struts2 Action获取表单数据的方式有三种:1.通过属性驱动的方式.2.模型驱动方式.3.使用多个model对象的属性. 1.通过属性驱动式 首先在jsp里面编写form表单的代码如下: & ...
- 2016/10/29 Action类中execute方法的使用
第一步:先配置web.xml文件 <filter> <filter-name>struts2</filter-name> <filter-class>o ...
- 通过button将form表单的数据提交到action层
form表单中不需要写action的路径,需要给form表单一个唯一的id,将你要提交的信息的表单中的标签name="action中的javabean对象.javabean属性". ...
- form表单提交路径action="" 时的一种特殊情况
一.说明: 当页面的form表达的action=""时,表示表单会提交到当前页面,但是如果当前页面的URL里已经带有一个参数了,每次提交表达时这个参数依然存在,不管form表单里有 ...
- Liferay7 BPM门户开发之40: Form表单的Action到Render的数据传递
在Form提交后的变量,很多情况是要展现在jsp页面中,这时Action到Render的变量传递就非常有用. 例如,您在数据库中添加了学生的详细信息. 为了实现这一需求,先创建Form表单(学生的细节 ...
- Form表单中的action路径问题,form表单action路径《jsp--->Servlet路劲问题》这个和上一个《jsp--->Servlet》文章有关
Form表单中的action路径问题,form表单action路径 热度5 评论 50 www.BkJia.Com 网友分享于: 2014-08-14 08:08:01 浏览数44525次 ...
- Js document.frmLogin.action = '/login.htm';的意义和form表单的target属性
一.解答:就是把 这个id名为frmLogin的form的提交地址改为上面的/login.htm <form id="frmLogin" name="frmLogi ...
- form 表单 action 参数 接收不了
<form method="get" action="/test/index.php?mod=123456" > <input type=&q ...
- asp.net使用post方式action到另一个页面,在另一个页面接受form表单的值!(报错,已解决!)
原文:asp.net使用post方式action到另一个页面,在另一个页面接受form表单的值!(报错,已解决!) 我想用post的方式把一个页面表单的值,传到另一个页面.当我点击Default.as ...
随机推荐
- win8 metro 自己写摄像头录像项目
这是要求不适用CameraCaptureUI等使用系统自带的 camera UI界面.要求我们自己写调用摄像头摄像的方法,如今我把我的程序贴下: UI界面的程序: <Page x:Class= ...
- css中使input输入框与img(图片)在同一行居中对齐
input,img{vertical-align:middle;},同时设置input和img的vertical-align属性,兼容ie7
- 搜索学术论文訪问google的能用的几个IP地址
google搜索引擎打不开时的解决的方法,谷歌(google)的IP是多少? google IP镜像. 这里搜集了几个经过測试可用的IP,用来在不能域名訪问google的时候进行訪问 更新一个最新的. ...
- MyEclipse搭建SSH(Struts2+Spring2+Hibernate3)框架项目教程
对Struts.spring.hibernate大体上了解一遍后,就是针对这个几个框架的整合了. 怎样整合,请看以下: 第一:Struts2的jar和xml配置文件: jar包: commons-fi ...
- c中常用的关键字static const volatile
在C语言中,关键字static有三个明显的作用:1). 在函数体,一个被声明为静态的变量在这一函数被调用过程中维持其值不变.2). 在模块内(但在函数体外),一个被声明为静态的变量可以被模块内所用函数 ...
- CodeSmith连Oracle
据说CodeSmith连Oracle特别麻烦,什么WIN7下不行,64位下不行.之前有个同事为了用上CodeSmith,还特地装了个XP虚拟机. 其实,还是那个连接串的问题. 操作系统64位,就要用6 ...
- Android-support-v4源码查看
- ubuntu查看文件的权限
查看linux文件的权限: 查看path路径下名为filename的文件或文件夹的权限: ls -l path/filename ls -l path/filename 查看path路径下的所有文件的 ...
- Synthesizing Images of Humans in Unseen Poses
Synthesizing Images of Humans in Unseen Poses balakg/posewarp-cvpr2018 https://github.com/balakg/pos ...
- 临时表 数据在 内存 转移时间 将160秒的创建临时表时间放入定时任务 不到1秒的求和时间 hadoop 引入Hadoop 分布式计算
SELECT SUM(pv) as pv_t FROM 行 112247817表类型 InnoDB自动递增值 1082428327行格式 Compact索引长度 8.60 GB (9,235,93 ...