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 ...
随机推荐
- Deepin-安装php
点击即可:下载:PHP5.6 下载完后执行下面这条shell命令即可完成安装 文件保存为:php_install.sh ,运行时:sh php_install.sh .tar.bz2 cd php- ...
- 分享一个检测用户是否用手机(Mobile)访问网站的 PHP 类
有一个基于MIT License协议开源的PHP程序 http://code.google.com/p/php-mobile-detect/ 程序就是一个文件,下载之后直接引用就可以. 使用方法: & ...
- antd 表单验证
antd form 自带方法 /** * 获取 form 自带方法 * getFieldDecorator * getFieldsError * getFieldError * isFieldTou ...
- activiti自己定义流程之自己定义表单(一):环境配置
先补充说一下自己定义流程整个的思路,自己定义流程的目的就是为了让一套代码解决多种业务流程.比方请假单.报销单.採购单.协作单等等.用户自己来设计流程图. 这里要涉及到这样几个基本问题,一是不同的业务需 ...
- Scrum 每日站会
站立式会议(Daily Scrum, 有时候我们直接叫做Daily Meeting)是Scrum敏捷软件开发方法学的实践之一,也是团队最容易实施的敏捷实践,实施成本低. 具体做法,团队成员每天固定时间 ...
- 发现个delphi调用vc写的Dll中包括pchar參数报错奇怪现象
发现个delphi调用vc写的Dll中包括pchar參数奇怪现象 procedure中的第一行语句不能直接调用DLL的函数,否则会执行报错,在之前随意加上条语句就不报错了奇怪! vc的DLL源代码地址 ...
- grep命令最经常使用的功能总结
1. grep最简单的用法,匹配一个词:grep word filename 2. 能够从多个文件里匹配:grep word filename1 filenam2 filename3 3. 能够使用正 ...
- C/C++ scanf 函数中%s 和%c 的简单差别
首先声明:在键盘中敲入字符后,字符会首先保存在键盘缓冲区中供scanf函数读取(scanf.getchar等函数是读取缓冲区,getch函数是读取的控制台信息,即为直接从键盘读取).另外特别注意键盘上 ...
- 搭建gitserver
1.下载gitosis代码出错 git clone git://eagain.net/gitosis.git Initialized empty Git repository in /tmp/gito ...
- WWDC笔记:2011 Session 125 UITableView Changes, Tips and Tricks
What’s New Automatic Dimensions - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSect ...