你在jsp中用的struts的标签来传值的..

解决方案 »

  1.   

    我知道是这么做的
    可是我不知道怎么把数据库得到的值放入taglib中
    能在具体点吗
      

  2.   

    楼主能不能举个struts的实例,我搞了2天也没实现,好像知道是那么回事,就是运行不通过
      

  3.   

    我也不明白啊
    我现在只能是懂了半个struts,在页面的显示上我还是不懂
      

  4.   

    你下载来的struts包,解压缩。有一些war文件
    你吧他们copy到tomcat的wepapp目录下就可以自动部署了有好几个示例,慢慢研究吧:)
      

  5.   

    如果你要将要显示的数据,需要在action里将数据封装到actionForm里,然后根据struts-config.xml文件里的配置,将actioinForm保存到对应的变量的属性中(变量指的是request ,session,application),影响保存方式的配置元素主要是action元素里的name,attribute和scope属性,attribute属性指出了保存的属性名,如果没有指定就使用name属性,scope指出保存的作用域。在action执行完必返回到jsp页面的时候,页面的html:form元素根据struts-config.xml文件里的配置(同上),来取出actionForm,然后将里面的数据显示出来。
      

  6.   

    显示一般是在action里把数据组装好 比如放到一个bean里 然后把该bean存到request.setAttribute("beanname",mybean);然后return mapping.findForward(目标);
    该目标在struts-config.xml中定义然后在你显示的jsp 可以用<bean:write name="employee" property="username" />
    或者在前面通过request.getAttribute("beanname");接下来就跟以前的差不多了!
      

  7.   

    显示一般是在action里把数据组装好 比如放到一个bean里 然后把该bean存到request.setAttribute("beanname",mybean);然后return mapping.findForward(目标);
    该目标在struts-config.xml中定义然后在你显示的jsp 可以用<bean:write name="employee" property="username" />
    或者在前面通过request.getAttribute("beanname");接下来就跟以前的差不多了!
      

  8.   

    you have 3 ways to pass value from action class to jsp:-- form bean (form.setXXX())
    -- request (request.setAttribute())
    -- session (session.getAttribute())dont recommend other places like servletContext.In jsp, all objects are viewed as java beans.the order of looking is from form to request, to sessin.
      

  9.   

    youfly等  讲解的非常好了,又穿了一便,谢谢。
      

  10.   

    <%// $Id: add.jsp,v 1.8 2000/02/15 14:49:51 gongke Exp $%>
    <%@ page contentType="text/html; charset=gb2312" %>
    <%@ include file="../../inc/head.jsp"%>
    <%@ include file="../../js/util.js"%>
    <%@ page import="sun.jdbc.rowset.CachedRowSet"%>
    <jsp:useBean id="major" class="peiyang.xueji.Major"/>
    <jsp:useBean id="advisor" class="peiyang.jiaowu.Advisor"/>
    <jsp:useBean id="direction" class="peiyang.jiaowu.Direction" scope="request">
    <jsp:setProperty name="direction"  property="*"/>
    </jsp:useBean>
    <%
    direction.loadRecord();//将数据库中的记录复制给bean 
    %>
    <html>
    <head>
    <title>
    </title>
    <link rel="stylesheet" href="../../inc/main.css" type="text/css">
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    </head><body background=../../images/line.gif >
    <center>
      <br>
      <script>
      function check(){
        if (!IsNumeric(form1.directionId.value)){
      alert ('方向编号应该是数字') ;
      form1.directionId.focus();
      return false;
    }
    if (form1.directionId.value==''){
      alert ('请填写方向编号');
      form1.directionId.focus();
      return false;
    }
    if (form1.directionName.value==''){
      alert ('请填写方向的名称');
      form1.directionName.focus();
      return false;
    }
    }
      </script>
      <form name="form1" method="post" action="process.jsp" onSubmit="return check()">
        <table cellpadding=0 cellspacing=0 border=0 width="600">
          <tr height=25> 
            <td class=cl1_titleoff align=center colspan=2><font class=m2_1>添加方向</font></td>
          </tr>      <tr> 
            <td class="mode4"> <img src=../../images/blank.gif width=10 height="8">方向编号</td>
            <td class="mode5"> <img src=../../images/blank.gif width=10 height="8"> 
              <input name="directionId" type="text" id="directionId" value="<jsp:getProperty name="direction" property="directionId"/>" maxlength="20"> 
            </td>
          </tr>      <tr> 
            <td class="mode4"> <img src=../../images/blank.gif width=10 height="8">方向名称</td>
            <td class="mode5"> <img src=../../images/blank.gif width=10 height="8"> 
              <input name="directionName" type="text" id="directionName" value="<jsp:getProperty name="direction" property="directionName"/>" size="50" maxlength="100" > 
            </td>
          </tr>
          <tr> 
            <td class="mode4"> <img src=../../images/blank.gif width=10 height="8">方向描述</td>
            <td class="mode5"><img src=../../images/blank.gif width=10 height="1">
    <textarea name="directionDescription" cols="50" rows="5" id="directionDescription"><jsp:getProperty name="direction" property="directionDescription"/></textarea> 
            </td>
          </tr>
          <tr> 
            <td class="mode4"> <img src=../../images/blank.gif width=10 height="8">学科带头人</td>
            <td class="mode5"> <img src=../../images/blank.gif width=10 height="8"> 
              <select name="advisorId" id="advisorId">
                <%
      CachedRowSet rs=advisor.getList(" where schoolId='"+request.getParameter("schoolId")+"'");
      while(rs.next()){
        out.println("<option value='"+rs.getString("advisorId")+"'>"+rs.getString("advname")+"</option>");
      }
      %>
              </select> </td>
          </tr>
          <tr> 
            <td class="mode4"> <img src=../../images/blank.gif width=10 height="8">开设日期</td>
            <td class="mode5"> <img src=../../images/blank.gif width=10 height="8"> 
              <strong> 
              <%
    out.println(util.time.DateTimeUtil.dateList("setupDate",request.getParameter("setupDate_y"),request.getParameter("setupDate_m"),request.getParameter("setupDate_d"),1945,2010));
    %>
              </strong> </td>
          </tr>
          <tr> 
            <td class="mode4"> <img src=../../images/blank.gif width=10 height="8">备注</td>
            <td class="mode5"> <div class="box"> <img src=../../images/blank.gif width=10 height="1"> 
                <input name="note" type="text"  id="note" value="<jsp:getProperty name="direction" property="note"/>" maxlength="20">
              </div></td>
          </tr>
          <tr> 
            <td class="mode4"> <img src=../../images/blank.gif width=10 height="8">相关操作</td>
            <td bgcolor="fafafa" class="mode5"><img src=../../images/blank.gif width=10 height="8"> 
              <input name="add" type="submit" class="cl2_ipt" value="添加">
              <input name="action" type="hidden" id="action2" value="add"> <input name="button" type="button" class="cl2_ipt" value="返回" onClick="window.location='index.jsp'"> 
              <input name="majorId" type="hidden" id="majorId2" value="<%=request.getParameter("majorId")%>">
              <input name="schoolId" type="hidden" id="schoolId" value="<%=request.getParameter("schoolId")%>">
              注意:请先初始化学院、方向、导师数据后在录入本数据</td>
          </tr>
        </table>
        
      </form>
      <br>
    </center>
    </body>
    </html>