Struts bean:write filter

Struts中的<bean:write name="neeke" scope="request" />标签相当于<%=request.getAttribute("neeke")%>,当然这里也不一定是request,也可能是session等,其中neeke是属性的名字。

首先我们来看一看action中的代码。

 
  1. package cn.ineeke.struts;
  2.  
  3. import javax.servlet.http.HttpServletRequest;
  4. import javax.servlet.http.HttpServletResponse;
  5.  
  6. import org.apache.struts.action.Action;
  7. import org.apache.struts.action.ActionForm;
  8. import org.apache.struts.action.ActionForward;
  9. import org.apache.struts.action.ActionMapping;
  10.  
  11. public class BeanWriteAction extends Action {
  12.  
  13.     @Override
  14.     public ActionForward execute(ActionMapping mapping, ActionForm form,
  15.             HttpServletRequest request, HttpServletResponse response)
  16.             throws Exception {
  17.             request.setAttribute("myblog""<a href=’http://www.ineeke.com’>http://www.ineeke.com</a>");
  18.             return mapping.findForward("success");
  19.     }
  20.  
  21. }

上面这段代码的作用很简单,就是向request中存值,接着跳转到成功页面。再来看看成功页的代码是什么样的。

 
  1. <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
  2. <%@ taglib prefix="bean" uri="http://struts.apache.org/tags-bean" %>
  3. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  4. <html>
  5.   <head> 
  6.     <title>Struts标签BeanWrite学习</title>
  7.   </head>
  8.   <body>
  9.     <bean:write name="myblog" scope="request"/>
  10.   </body>
  11. </html>

在上面的代码中,我们使用<bean:write>标签从request中将myblog取出并显示在网页上。此时是按照文本格式直接输出的,而我们存放的时候是带HTML代码的,如果我们想让它以超级链接的形式显示在网页中呢?
其实这很简单,此标签有一个filter属性,其意在于是否以文本格式输出,默认情况下其值为true,所以我们只需将其改为如下所示即可。
<bean:write name="myblog" scope="request" filter="false"/>


除非另有声明,本站遵循【署名-非商业性使用-相同方式共享 3.0 共享协议】授权。

转载原创文章请注明,转载自:Neeke[http://www.ineeke.com]

本文链接: http://www.ineeke.com/archives/StrutsBeanWriteFilter/

2008年12月13日 | 归档于 J2EE技术 | 1 条评论
  1. 2008年12月14日 13:02 | #1


    又没看懂~

发表评论

XHTML: 您可以使用这些标签: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">
n:-zy n:-zr n:-zan n:-xf n:-wx n:-tz n:-tt n:-ts n:-sy n:-st n:-ss n:-sk n:-qd n:-pz n:-lh n:-kun n:-ku n:-hx n:-hd n:-gt n:-gg n:-bz

NOTICE: You should type some Chinese word (like “你好”) in your comment to pass the spam-check, thanks for your patience!