1>web.xml

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  3. xmlns="http://xmlns.jcp.org/xml/ns/javaee"
  4. xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
  5. id="WebApp_ID" version="3.1">
  6. <display-name>Test</display-name>
  7. <welcome-file-list>
  8. <welcome-file>index.html</welcome-file>
  9. <welcome-file>index.htm</welcome-file>
  10. <welcome-file>index.jsp</welcome-file>
  11. <welcome-file>default.html</welcome-file>
  12. <welcome-file>default.htm</welcome-file>
  13. <welcome-file>default.jsp</welcome-file>
  14. </welcome-file-list>
  15. <filter>
  16. <filter-name>struts2</filter-name>
  17. <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
  18. </filter>
  19. <filter-mapping>
  20. <filter-name>struts2</filter-name>
  21. <url-pattern>/*</url-pattern>
  22. </filter-mapping>
  23. </web-app>

2>userAction.java

  1. package com.Test.action;
  2.  
  3. public class UserAction {
  4. String info;
  5.  
  6. public String getInfo() {
  7. return info;
  8. }
  9.  
  10. public void setInfo(String info) {
  11. this.info = info;
  12. }
  13.  
  14. public String find() {
  15. if (info.endsWith(".vip")) {
  16. return "vip";
  17. }
  18. return "regular";
  19. }
  20. }

3>struts.xml

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE struts PUBLIC
  3. "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
  4. "http://struts.apache.org/dtds/struts-2.3.dtd">
  5. <struts>
  6. <!-- 动态方法调用 -->
  7. <constant name="struts.enable.DynamicMethodInvocation" value="true" />
  8. <package name="helloPackage" extends="struts-default">
  9. <action name="userAction" class="com.Test.action.UserAction" method="find">
  10. <result name="vip">/vip.jsp</result>
  11. <result name="regular">/nvip.jsp</result>
  12. </action>
  13. </package>
  14. </struts>

4>index.jsp

  1. <%@ page language="java" contentType="text/html; charset=UTF-8"
  2. pageEncoding="UTF-8"%>
  3. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  4. <html>
  5. <head>
  6. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  7. <title>Insert title here</title>
  8. </head>
  9. <body>
  10. <form action="userAction">
  11. <table border="1" width="400px" height="200px">
  12. <tr>
  13. <td>请输入用户名:</td>
  14. <td><input name="info" type="text" /></td>
  15. </tr>
  16. <tr>
  17. <td colspan="2"><input type="submit" name="submit" value="提交" /></td>
  18. </tr>
  19. </table>
  20. </form>
  21. </body>
  22. </html>

5>相关jsp文件

  1. <%@ page language="java" contentType="text/html; charset=UTF-8"
  2. pageEncoding="UTF-8"%>
  3. <%@taglib prefix="s" uri="/struts-tags"%>
  4. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  5. <html>
  6. <head>
  7. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  8. <title>Insert title here</title>
  9. </head>
  10. <body>
  11. <h1>VIP</h1>
  12. <s:property value="info" />
  13. </body>
  14. </html>

vip.jsp

  1. <%@ page language="java" contentType="text/html; charset=UTF-8"
  2. pageEncoding="UTF-8"%>
  3. <%@taglib prefix="s" uri="/struts-tags"%>
  4. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  5. <html>
  6. <head>
  7. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  8. <title>Insert title here</title>
  9. </head>
  10. <body>
  11. <h1>NOT VIP ,HELLOWORLD</h1>
  12. <s:property value="info" />
  13. </body>
  14. </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. Deepin-安装php

    点击即可:下载:PHP5.6 下载完后执行下面这条shell命令即可完成安装 文件保存为:php_install.sh ,运行时:sh php_install.sh .tar.bz2 cd php- ...

  2. 分享一个检测用户是否用手机(Mobile)访问网站的 PHP 类

    有一个基于MIT License协议开源的PHP程序 http://code.google.com/p/php-mobile-detect/ 程序就是一个文件,下载之后直接引用就可以. 使用方法: & ...

  3. antd 表单验证

    antd  form 自带方法 /** * 获取 form 自带方法 * getFieldDecorator * getFieldsError * getFieldError * isFieldTou ...

  4. activiti自己定义流程之自己定义表单(一):环境配置

    先补充说一下自己定义流程整个的思路,自己定义流程的目的就是为了让一套代码解决多种业务流程.比方请假单.报销单.採购单.协作单等等.用户自己来设计流程图. 这里要涉及到这样几个基本问题,一是不同的业务需 ...

  5. Scrum 每日站会

    站立式会议(Daily Scrum, 有时候我们直接叫做Daily Meeting)是Scrum敏捷软件开发方法学的实践之一,也是团队最容易实施的敏捷实践,实施成本低. 具体做法,团队成员每天固定时间 ...

  6. 发现个delphi调用vc写的Dll中包括pchar參数报错奇怪现象

    发现个delphi调用vc写的Dll中包括pchar參数奇怪现象 procedure中的第一行语句不能直接调用DLL的函数,否则会执行报错,在之前随意加上条语句就不报错了奇怪! vc的DLL源代码地址 ...

  7. grep命令最经常使用的功能总结

    1. grep最简单的用法,匹配一个词:grep word filename 2. 能够从多个文件里匹配:grep word filename1 filenam2 filename3 3. 能够使用正 ...

  8. C/C++ scanf 函数中%s 和%c 的简单差别

    首先声明:在键盘中敲入字符后,字符会首先保存在键盘缓冲区中供scanf函数读取(scanf.getchar等函数是读取缓冲区,getch函数是读取的控制台信息,即为直接从键盘读取).另外特别注意键盘上 ...

  9. 搭建gitserver

    1.下载gitosis代码出错 git clone git://eagain.net/gitosis.git Initialized empty Git repository in /tmp/gito ...

  10. WWDC笔记:2011 Session 125 UITableView Changes, Tips and Tricks

    What’s New Automatic Dimensions - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSect ...