您的位置:首页 > 编程语言 > Java开发

struts-标签的使用(二)

2017-08-20 15:57 225 查看
<%@page import="po.Student,java.util.*"%>
<%@ page language="java" pageEncoding="UTF-8"%>

<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html:html lang="true">
<head>
<title>MyJsp.jsp</title>
</head>

<body>
这是第一个页面
<a href="jsp2.jsp">链接1</a><br>
<html:link page="/jsp2.jsp">链接2</html:link><br>
<html:link href="jsp2.jsp">链接3</html:link><br>
<html:link forward="JSP2">链接4</html:link>
<html:link action="/xxx.do">链接5(适合链接的同时还作一些操作的情况)</html:link>
<hr>
<html:link page="/jsp2.jsp?param=0001">到达jsp2,传参数1</html:link><br>
<%
request.setAttribute("msg", "<b>0001</b>");

//
Student stu=new Student();
stu.setUserID("0001");
session.setAttribute("stu", stu);

//多个参数可以放入HashMao
HashMap<String,String> hm=new HashMap<String,String>();
hm.put("param1", "msg1");
hm.put("param2", "msg2");
hm.put("param3", "msg3");
session.setAttribute("paramList", hm);

Cookie c=new Cookie("username","Kate");
c.setMaxAge(1000*60);
response.addCookie(c);

%>
<html:link page="/jsp2.jsp" paramId="param" paramName="msg" >到达jsp2,传参数2</html:link><br>
<html:link page="/jsp2.jsp" paramName="stu" paramId="param" paramProperty="userID"></html:link>
<html:link page="/jsp2.jsp" name="paramList" >到达jsp2,传参数3</html:link>
</body>
</html:html>
<%@page import="po.Student" %>
<%@ page language="java" pageEncoding="UTF-8"%>

<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html" %>
<%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic" %>
<%@ taglib uri="http://struts.apache.org/tags-tiles" prefix="tiles" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html:html lang="true">
<head>
<title>jsp2.jsp</title>

</head>

<body>
获得参数param:<%=request.getParameter("param") %><br>
获得参数param:
<bean:parameter name="param" id="str"/>
<bean:write name="str" filter="false"/><br>
显示JavaBean内的属性(stu从session内得到):<bean:write name="stu" property="userID"/>
Cookie的值:<bean:cookie name="username" id="cookie1"/><bean:write name="cookie1" property="value"/>
<!-- 判断str是否等于0001,是就显示"OK" -->
<logic:equal name="str" value="0001">
OK
</logic:equal>
</body>
</html:html>


---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
<%@ page language="java" pageEncoding="UTF-8"%>
<%@page import="java.util.*,po.Student" %>
<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html" %>
<%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic" %>
<%@ taglib uri="http://struts.apache.org/tags-tiles" prefix="tiles" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitiona
4000
l//EN">
<html:html lang="true">
<head>
<html:base />
<title>jsp3.jsp</title>
</head>

<body>
这是第三个页面<br>
<html:link href="jsp4.jsp">跳转到页面4</html:link>
<%
//简单集合:集合(数组)里面是i暗淡数据
ArrayList<String> books=new ArrayList<String>();
books.add("三国演义");
books.add("水浒传");
books.add("西游记");
session.setAttribute("books", books);

//集合里面含有 JavaBean
ArrayList<Student> stus=new ArrayList<Student>();
Student stu1=new Student(); stu1.setUserID("0001");
Student stu2=new Student(); stu2.setUserID("0002");
Student stu3=new Student(); stu3.setUserID("0003");
stus.add(stu1);
stus.add(stu2);
stus.add(stu3);
session.setAttribute("stus", stus);
//javaBean里面有集合
Student stu4=new Student();
ArrayList phones=new ArrayList();
phones.add("123123");
phones.add("34534543");
stu4.setPhone(phones);
session.setAttribute("stu4", stu4);
//复杂契合:以HashMap为代表
HashMap<String,String> hm=new HashMap<String,String>();
hm.put("param1", "msg1");
hm.put("param2", "msg2");
hm.put("param3", "msg3");
session.setAttribute("hm", hm);
%>
</body>
</html:html>

<%@ page language="java" pageEncoding="UTF-8"%>

<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html" %>
<%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic" %>
<%@ taglib uri="http://struts.apache.org/tags-tiles" prefix="tiles" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html:html lang="true">
<head>
<title>jsp4.jsp</title>
</head>

<body>
这是第四个页面<br>
简单集合:
<logic:iterate id="book" name="books">
<bean:write name="book"/>
</logic:iterate><hr>
集合里面含有javaBean
<logic:iterate id="stu" name="stus">
<bean:write name="stu" property="userID"/>
</logic:iterate><br>
JavaBean里有集合:
<logic:iterate id="stu_phones" name="stu4" property="phone">
<bean:write name="stu_phones"/>
</logic:iterate><br>
遍历HashMap:
<logic:iterate id="hm_key" name="hm">
<bean:write name="hm_key" property="value"/>

</logic:iterate>

</body>
</html:html>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: