Struts bean:write filter
Struts中的<bean:write name="neeke" scope="request" />标签相当于<%=request.getAttribute("neeke")%>,当然这里也不一定是request,也可能是session等,其中neeke是属性的名字。
首先我们来看一看action中的代码。
- package cn.ineeke.struts;
- import javax.servlet.http.HttpServletRequest;
- import javax.servlet.http.HttpServletResponse;
- import org.apache.struts.action.Action;
- import org.apache.struts.action.ActionForm;
- import org.apache.struts.action.ActionForward;
- import org.apache.struts.action.ActionMapping;
- public class BeanWriteAction extends Action {
- @Override
- public ActionForward execute(ActionMapping mapping, ActionForm form,
- HttpServletRequest request, HttpServletResponse response)
- throws Exception {
- request.setAttribute("myblog", "<a href=’http://www.ineeke.com’>http://www.ineeke.com</a>");
- return mapping.findForward("success");
- }
- }
上面这段代码的作用很简单,就是向request中存值,接着跳转到成功页面。再来看看成功页的代码是什么样的。
- <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
- <%@ taglib prefix="bean" uri="http://struts.apache.org/tags-bean" %>
- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
- <html>
- <head>
- <title>Struts标签BeanWrite学习</title>
- </head>
- <body>
- <bean:write name="myblog" scope="request"/>
- </body>
- </html>
在上面的代码中,我们使用<bean:write>标签从request中将myblog取出并显示在网页上。此时是按照文本格式直接输出的,而我们存放的时候是带HTML代码的,如果我们想让它以超级链接的形式显示在网页中呢?
其实这很简单,此标签有一个filter属性,其意在于是否以文本格式输出,默认情况下其值为true,所以我们只需将其改为如下所示即可。
<bean:write name="myblog" scope="request" filter="false"/>
除非另有声明,本站遵循【署名-非商业性使用-相同方式共享 3.0 共享协议】授权。
转载原创文章请注明,转载自:Neeke[http://www.ineeke.com]

欧
又没看懂~