日期:2014-05-19  浏览次数:20694 次

url修改的原因
项目的一个标签这样写到:
Java code

public class EncodeTag extends TagSupport {
    private String property;
    private Log logger = LogFactory.getLog(this.getClass());
    public int doStartTag() throws JspException {
         logger.debug(property);
         if(property==null){
             logger.debug("property is null");
             property = "";
         }
         StringBuffer sbuf = new StringBuffer();

         char[] chars = property.toCharArray();
         for (int i = 0; i < chars.length; i++) {
              sbuf.append("&#" + (int) chars[i]);
         }

         try{
              pageContext.getOut().print(sbuf.toString());
         } catch (IOException ex) {
              throw new JspException(ex.getMessage());
         }

         return SKIP_BODY;
     }


在页面对URL中的参数进行转换,请问为什么需要这样做?!是防止乱码吗?


------解决方案--------------------
我敢肯定不是防止乱码。
这个具体用途,要问你的项目经理(技术经理)。
------解决方案--------------------
都命名成了 EncodeTag 然后又把每个字符转换成int值。还加上&#来做切断 我觉得。。是用来防止乱码的 转换成 int 数值后就不存在编码问题了 特别在用get方法传值上 哈哈哈 问问他吧
------解决方案--------------------
结贴了!。。。。
------解决方案--------------------
是普通的http地址拼接了
sbuf.append("&#" + (int) chars[i]);

但是这句话的意思我就不明白了!
return SKIP_BODY;

------解决方案--------------------
作用跟把 < 变成 &lt; > 变成 &gt; 一样,为了把property忠实显示出来。