现在的位置: 首页 > 综合 > 正文

Java 后能执行JS(JSF)

2012年09月25日 ⁄ 综合 ⁄ 共 868字 ⁄ 字号 评论关闭
 1public static void RunJs(String js) {
 2        FacesContext ctx = FacesContext.getCurrentInstance();
 3        String contentType = "text/html;charset=utf-8";
 4        HttpServletResponse response = (HttpServletResponse) ctx
 5                .getExternalContext().getResponse();
 6        response.setContentType(contentType);
 7        ServletOutputStream out = null;
 8        try {
 9            out = response.getOutputStream();
10        }
 catch (IOException e) {
11            // TODO Auto-generated catch block
12            e.printStackTrace();
13        }

14        StringBuffer buf = new StringBuffer();
15        buf.append("<script type=\"text/javascript\">"+js+"</script>");
16        try {
17            out.print(buf.toString());
18        }
 catch (IOException e) {
19            // TODO Auto-generated catch block
20            e.printStackTrace();
21        }

22    }

抱歉!评论已关闭.