可以;但是到浏览器端时,JSP已经运行过了

解决方案 »

  1.   

    可以,牢记在后台时只有jsp代码,javascript当字符串.到前台后,没有
    jsp代码,都是根据条件产生的html等代码。
      

  2.   

    我是这样设计的
    我在提交表单的时候进行有效性判断
    我写了一个函数进行判断
    比如有些文本框不能为空,但是这些不能为空的文本框我是根据数据库表中对应的值确定的,所以我在函数中应该嵌入jsp代码,
    但是运行的时候编译器不认,请问是什么问题
      

  3.   

    使用style="width:100%;isnullable:0",其中isnullable用JSP代码或手动给出<script language="JavaScript">
    <!--
    function MM_goToURL() { //v3.0
      var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
      for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
    }String.prototype.Trim = function(){
      return this.replace(/(^\s*)|(\s*$)/g, "");
    }function check(){
      var inputs=document.frmAdd.all.tags("INPUT");  for(var i=0;i<inputs.length;i++){
        //去掉所填项目左右空格
        var tmp=inputs[i].value;
        inputs[i].value=tmp.Trim();    //如果必填项未填,要求填写
        if(inputs[i].value.length<=0 && inputs[i].style.isnullable==0){
          alert("带有'*'号的项目为必填项目,请全部填写。");
          return false;
        }    //如果有File字段且不为空,则改变表单的提交类型
        if(inputs[i].value.length>0 && inputs[i].type.toUpperCase()=="FILE"){
          document.frmAdd.enctype="multipart/form-data";
        }
      }//end for(var i=0;i<inputs.length;i++)  if(document.frmAdd.enctype=="multipart/form-data") document.frmAdd.action="";
      else document.frmAdd.action="PDMAdd.jsp";
      return true;
    }
    //-->
    </script></head>
    <body>
    <form name=frmAdd method="POST" onsubmit="return check()" >
      <div align="center">
        <table border="1" cellspacing="0" width="60%"
      bgcolor="#F0F8FF" bordercolorlight="#11B1FF" bordercolordark="#F0F8FF">
          <tr>
            <td width="100%" bgcolor="#0080C0" height="20">
              <div align="center">
                <p><b><font
          color="#FFFFFF">添加新记录</font></b>
              </div>
            </td>
          </tr>
          <tr align="center">
            <td width="100%">
              <table bgColor=#f0f8ff border=1 borderColorDark=#ecf5ff  borderColorLight=#4da6ff cellSpacing=0 width="100%">            <tr>
                  <td width="38%" align="left" height="30" nowrap> <b><font color="#0080C0">
                    权限编码<font color=#FF0000 > *</font></font></b></td>
                  <td width="62%" height="30">
                    <input type="Text" value=
                    "" name="Code" size="70" class="smallinput" style="width:100%;isnullable:0">
                  </td>
                </tr>            <tr>
                  <td width="38%" align="left" height="30" nowrap> <b><font color="#0080C0">
                    权限级别<font color=#FF0000 > *</font></font></b></td>
                  <td width="62%" height="30">
                    <input type="Text" value=
                    "" name="Class" size="70" class="smallinput" style="width:100%;isnullable:0">
                  </td>
                </tr>            <tr>
                  <td width="38%" align="left" height="30" nowrap> <b><font color="#0080C0">
                    说明<font color=#FF0000 > *</font></font></b></td>
                  <td width="62%" height="30">
                    <input type="Text" value=
                    "" name="Re" size="70" class="smallinput" style="width:100%;isnullable:0">
                  </td>
                </tr>
             </table>
            </td>
          </tr>
        </table>
      </div>
      <div align="center">
        <p>
          <input type="submit" value=" 确  定 " name="cmdok" class="buttonface" >
          &nbsp;
          <input type="reset" value=" 复  原 " name="cmdcancel" class="buttonface">
          &nbsp;
          <input type="button" value=" 返  回 " name="cmdreturn" class="buttonface" onclick="MM_goToURL('self','http://localhost:8080/PDMShow.jsp');return document.MM_returnValue">
        </p>
      </div>
    </form>
    </body>
    </html>
      

  4.   

    你说的方法是可行
    不过你的意思是javascript函数中不能嵌入jsp代码吧
      

  5.   

    可以嵌入呀。
    test.jsp:
    strIsNullable=0;
    <input name=like style="width:100%;isnullable:<%=strIsNullable%>">到浏览器端时,代码就会变成:
    <input name=like style="width:100%;isnullable:0">这个不需要解释吧?只是弄不明白你所谓“嵌入”的概念:javascript和JSP代码是不能同时起作用的。
      

  6.   

    在函数外是能够嵌入的
    我是说函数中能否嵌入jsp代码