好象在javabean中不能输出脚本语句,在servlet中是可以的

解决方案 »

  1.   

    应该不用这样做,如果想输出语句,直接用jsp就好了,没有必要用bean了用bean的目的就是要把叶面和脚本分开的阿
      

  2.   

    package com.你定义的包;public final class JS{ private static String b = "<script language=\"JavaScript\">" ;
    private static String e = "</script>" ; public static String alert(String strAlert){
    return b+"    window.alert('"+strAlert+"') ;" +e ;
    } public static String go(String strUrl){
    return b+"    window.location.href='"+strUrl+"' ;" +e ;
    } public static String go(int n){
    return b+"    history.go("+n+"); "+e ;
    } public static String code(String jscode){
    return b+ jscode +e ;
    }}我定义了alert,go,code方法,你也可以根据实际具体定义
    调用时不用new就行,for example:JS.alert("禁止访问!");
      

  3.   

    很不好的习惯
    脚本在jsp里写就ok了!
      

  4.   

    其实我觉得jsp就这点不好
    我想要递归调用一个函数来out.print一些东西可是就是无法用函数实现只好嵌套循环了
      

  5.   

    html语句最好是在jsp中显示,只有在特殊情况下要在javaBean里生成html语句,我一般都是将html语句用赋值给字符串传回来。