java中占位符出错的问题

来源:互联网 发布:微交易源码买卖 编辑:程序博客网 时间:2024/05/06 06:22

String content = MessageFormat.format("<a href=‘http://localhost:8080/bookstore/UserServlet?method=active&code={0}’>点击这里完成注册</a>",form.getCode());

当我使用上面这条语句时,code总为{0},也就是说占位符有问题,form.getcode(0)没有替换{0}


正确应这样写:

String content = MessageFormat.format("<a href=http://localhost:8080/bookstore/UserServlet?method=active&code={0}>点击这里完成注册</a>",form.getCode());

就是http前和{0}后不要有 ’ 这个符号


我感觉是,在字符串里的字符串使用占位符,是没法替换的

0 0