现在有这样的一个字符串
<Order>
  <name>${person.name}</name>
</Order>
经过转换后
<Order>
  <name>张三</name>
</Order>各位大虾有没有这样的框架,如果没有框架,自己实现该怎么做

解决方案 »

  1.   

    片段代码:
    java文件:
    package com.org.mvc2.tag;import javax.servlet.jsp.JspException;/**
     * 输出作用域的值
     * @version 2.0
     */
    public class PrintTag extends BaseTag { private static final long serialVersionUID = 1L;
    private String name;
    private String scope; public int doStartTag() throws JspException {
    int index = getNumberSign(name);
    Object object = getObject(index, name, scope);
    if (null != object) {
    if (index >= 0) {
    write(getOperatValue(name, object, index));
    } else {
    write(object.toString());
    }
    }
    return SKIP_BODY;
    } /**
     * 取值的依据
     * @param name
     */
    public void setName(String name) {
    this.name = name;
    } /**
     * 取值作用域
     * @param scope 默认优先级为page--request--session--application
     */
    public void setScope(String scope) {
    this.scope = scope;
    }}tld文件:
    <tag>
    <description>输出作用域的值</description>
       <name>print</name>
       <tag-class>com.org.mvc2.tag.PrintTag</tag-class>
       <body-content>empty</body-content>
       <attribute>
       <description>取值的依据</description>
           <name>name</name>
           <required>true</required>
           <rtexprvalue>false</rtexprvalue>
         </attribute>
         <attribute>
       <description>取值的作用域,默认优先级为page--request--session--application</description>
           <name>scope</name>
           <required>false</required>
           <rtexprvalue>false</rtexprvalue>
         </attribute>
    </tag>jsp文件:
    <%@ page language="java" pageEncoding="GBK"%>
    <%@taglib prefix="m" uri="/mvc2"%>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
      <head>
        <title>My JSP 'index.jsp' starting page</title>
      </head>
      
      <body> 
    <Order>
      <name><m:print name="person.name"/></name>
    </Order>
      </body>
    </html>