我调用jsp时,语句是这样:
<form id="form1" name="form1" method="post" action="studentnum.jsp">
<input type="submit" name="biyezigeshencha" id="biyezigeshencha" value="毕业资格审查" />
<input name="renshu" type="text" id="renshu" size="5" maxlength="3" value="<%=getValue()%>">
而我的studentnum.jsp中的内容如下:   
<%! int num;
    public int getValue(){
     return num;}
     %>
<%
try{ 
    Conn_DbTest link=new Conn_DbTest(); 
    ResultSet rs=link.executeQuery("select count(*) from Student"); 
    num=rs.getInt(1);       
   }catch(Exception e){} 
%> 
我想将num值返回给文本框“renshu”,但是我的value="<%=getValue()%>">这行显示错误,如果将<%=getValue()%>改为<%=num%>那么这行还是错误,到底该怎样设计才能得到num值呀,求求各位了。

解决方案 »

  1.   

    此回复为自动发出,仅用于显示而已,并无任何其他特殊作用
    楼主【zhoutaibo】截止到2008-07-03 18:28:21的历史汇总数据(不包括此帖):
    发帖的总数量:20                       发帖的总分数:690                      
    结贴的总数量:18                       结贴的总分数:650                      
    无满意结贴数:0                        无满意结贴分:0                        
    未结的帖子数:2                        未结的总分数:40                       
    结贴的百分比:90.00 %               结分的百分比:94.20 %                  
    无满意结贴率:0.00  %               无满意结分率:0.00  %                  
    值得尊敬
      

  2.   


     public void setNum(int value){
        num=value;
     }  num=rs.getInt(1);    
      改为 setNum(re.getInt(1)) 
     
      

  3.   

    但是运行时,报这样的异常呀:
    org.apache.jasper.JasperException: Unable to compile class for JSP: An error occurred at line: 48 in the jsp file: /xueshengbiyeguanli.jsp
    The method getValue() is undefined for the type xueshengbiyeguanli_jsp
    45:                   <td>该班级共有学生:
    46:                    <label>
    47: <jsp:useBean id="myjsp" scope="page" class="MyPackeg.BiYeLink"></jsp:useBean>
    48:                     <input name="renshu" type="text" id="renshu" size="5" maxlength="3" value="<%=getValue()%>">
    49:                     人,目前暂不能取得毕业资格的学生:
    50:                     <input name="meibiye" type="text" id="meibiye" size="5" maxlength="3" />
    51:                     人。</label></td>
      

  4.   

    <form id="form1" name="form1" method="post" action="studentnum.jsp"> 
    <input type="submit" name="biyezigeshencha" id="biyezigeshencha" value="毕业资格审查" /> 
    <input name="renshu" type="text" id="renshu" size="5" maxlength="3" value=" <%=getValue()%>"> 执行这个页面的时候
    studentnum.jsp还没执行
    怎么会有num的值?
      

  5.   

    <form id="form1" name="form1" method="post" action="studentnum.jsp"> 
    <input type="submit" name="biyezigeshencha" id="biyezigeshencha" value="毕业资格审查" /> 
    <input name="renshu" type="text" id="renshu" size="5" maxlength="3" value=" <%=getValue()%>"> 

    上面的语句是哪一个jsp里的?不会是studentnum.jsp的吧?你应该在本页定义getValue方法,而不是在studentnum.jsp中。
      

  6.   

    这问题应该不难吧,
    楼主的意思应该是,表单递交给自身吧,然后取值显示在单行文本框里;首先要在HTML的表单加个隐藏框<input type="h.."(具体忘了用软件习惯生成了) name="cd">然后在文件最上面写接收参数(个人习惯,我一般写在上面);
    <% = request.getp....("xxx")%>
    在网吧没办法试,回家去写试试看
      

  7.   

    楼主犯了一个错误
    在<%!%>中声明的变量num
    和在<%%>中声明的变量num不是同一个变量
    所以当然会出错
      

  8.   

    <%! int num;
        public int getValue(){
           return num;
        }
        public void setValue(int num){
           this.num=num;
        }
    %>
    <%
    try{
        Conn_DbTest link=new Conn_DbTest();
        ResultSet rs=link.executeQuery("select count(*) from Student");
        num=rs.getInt(1);     
      }catch(Exception e){}
    %> 
    <input name="renshu" type="text" id="renshu" size="5" maxlength="3" value=" <%=this.getValue()%>"> <
      

  9.   

    不好意思,红色部分写错了
    <%! int num;
        public int getValue(){
          return num;
        }
        public void setValue(int num){
          this.num=num;
        }
    %>
    <%
    try{
        Conn_DbTest link=new Conn_DbTest();
        ResultSet rs=link.executeQuery("select count(*) from Student");
        this.setValue(rs.getInt(1));   
      }catch(Exception e){}
    %>
    <input name="renshu" type="text" id="renshu" size="5" maxlength="3" value=" <%=this.getValue()%>"> 
      

  10.   

    全部写在studentnum.jsp<form id="form1" name="form1" method="post" action="studentnum.jsp">
    <input type="submit" name="biyezigeshencha" id="biyezigeshencha" value="毕业资格审查" />
    <input name="renshu" type="text" id="renshu" size="5" maxlength="3" value=" <%=getValue()%>">
     
    <%! int num;
        public int getValue(){
        return num;}
        %>
    <%
    try{
        Conn_DbTest link=new Conn_DbTest();
        ResultSet rs=link.executeQuery("select count(*) from Student");
        num=rs.getInt(1);     
      }catch(Exception e){}
    %> 
      

  11.   

    The method getValue() is undefined for the type xueshengbiyeguanli_jsp 
    提示没有找到方法getValue() 
    原因:方法getValue()在studentnum.jsp中声明 所以在xueshengbiyeguanli_jsp找不到该方法  
    一般要取某个值可以通过传参数的方式
    在要取参数的页面用request.getParameter(String s)取
    比如:
    String num=requset.getParameter("num");
    然后
    <input name="renshu" type="text" id="renshu" size="5" maxlength="3" value=" <%=num>"> 
      

  12.   

    总结,出现这样的问题原因可以有2个,
    1.你在给num赋值前用了<%=getValue()%>
    2.你的web服务器版本问题,换个版本可能就好了。