OGNL表达式2
2015-10-30 15:12
176 查看
问题:OGNL常用相关标签的使用,OGNL表达式2的使用
案例:下载地点:点击打开链接 注:做该案例,前提是struts2的环境
1.struts.xml文件
两个action动作类
form.jsp页面:
效果:
案例:下载地点:点击打开链接 注:做该案例,前提是struts2的环境
1.struts.xml文件
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" "http://struts.apache.org/dtds/struts-2.0.dtd"> <struts> <package name="checkbox" namespace="/test" extends="struts-default"> <action name="checkboxAction" class="cn.itcast.web.domain.CheckBoxAction"> <result name="success">/form.jsp</result> </action> </package> </struts>
两个action动作类
package cn.itcast.web.domain; import java.io.Serializable; import com.opensymphony.xwork2.ActionSupport; public class CheckBoxAction extends ActionSupport implements Serializable { private String[] hobby1={"学习","打代码","程序"};//输入到jsp页面的选中值 private String[] hobby2;//得到的实际值 public String[] getHobby1() { return hobby1; } public void setHobby1(String[] hobby1) { this.hobby1 = hobby1; } public String[] getHobby2() { return hobby2; } public void setHobby2(String[] hobby2) { this.hobby2 = hobby2; } public String execute(){ hobby2=new String[]{"程序"}; return SUCCESS; } }
package cn.itcast.web.domain; import java.io.Serializable; public class Book implements Serializable { private String name; private float price; public Book(){ } public Book(String name, float price) { super(); this.name = name; this.price = price; } public String getName() { return name; } public void setName(String name) { this.name = name; } public float getPrice() { return price; } public void setPrice(float price) { this.price = price; } }
form.jsp页面:
<%@page import="cn.itcast.web.domain.Book"%> <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> <%@ taglib uri="/struts-tags" prefix="s" %> <% 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> <base href="<%=basePath%>"> <title>checkboxsList的用法</title> <meta http-equiv="pragma" content="no-cache"> <meta http-equiv="cache-control" content="no-cache"> <meta http-equiv="expires" content="0"> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv="description" content="This is my page"> <!-- <link rel="stylesheet" type="text/css" href="styles.css"> --> </head> <body> <s:form action="checkboxAction" namespace="/test"> <s:textfield name="username"></s:textfield> <s:password name="password"></s:password> <s:checkboxlist name="hobby" list="{'吃饭','睡觉','打豆豆'}" value="{'吃饭','打豆豆'}" ></s:checkboxlist> <h3>从action动作类传过来的checkbox值</h3> <s:checkboxlist list="hobby1" name="hh" value="hobby2"></s:checkboxlist> <h3>map类型的设定,listkey和listvalue反过来取值了。</h3> <s:checkboxlist list="#{'北京':'0','上海':'1','贵州':'2'}" name="province" listKey="value" listValue="key" value="{'2'}"></s:checkboxlist> <h3>从bean类book.class获取值</h3> <% List ps=new ArrayList(); ps.add(new Book("书1",2f)); ps.add(new Book("书2",3f)); ps.add(new Book("书3",4f)); request.setAttribute("ps", ps); %> <s:checkboxlist list="#request.ps" name="b" listKey="price" listValue="name"></s:checkboxlist> <!-- listKey="price" listValue="name" 这个写不写都可以。默认选上 --> <s:radio list="#{'0':'女','1':'男'}" listKey="key" listValue="value" ></s:radio> <s:select list="#{'12':'设定','13':'聚焦','14':'三农' }" value="'13'"></s:select> <!-- 这个要注意的是双引号里面到底当成的是字符串还是表达式不清楚的情况下,要是字符串,加上单引号即可 --> <s:submit value="提交"></s:submit> </s:form> </body> </html>
效果:
相关文章推荐
- Mongodb数据导出工具mongoexport和导入工具mongoimport介绍
- Spring测试工具返回Application
- ios使用webview浏览指定网页
- python--执行文件的绝对路径
- 虚幻引擎3的代码讲解
- 真机调试
- Android 屏蔽返回键、菜单键和Home键
- 2015多校第三场总结
- 用Windows Live Writer来写51CTO博客
- tomcat长连接、短连接配置及用途
- windows下sublime text 2的安装使用
- UE3代码阅读需知
- php 网上支付之易宝支付
- Mac下通过SSL获取RSA密钥与公钥
- h323协议 计算FPS 帧率
- 一个进程的诞生与死亡
- Java集合的总结
- 机器学习之基本算法总结
- SQL Server 海量数据查询代码优化以及建议
- 软件模拟I2C(基于Microchip 24LC16B的操作函数库)