DispatchAction:public ActionForward queryOneInviteJob(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
HttpSession session = request.getSession();
InviteJobActionFrom inviteForm=invitejob.getInviteJobById(new Integer(request.getParameter("id")));//根据ID查询,将结果放到inviteForm
request.setAttribute("form", inviteForm);//放到form中
return mapping.findForward("queryOneInviteJob");//转到JSP页面

}
JSP部分代码:<tr>
              <th width="69" height="30" class="word_white">姓名:</th>
              <td width="166" bgcolor="#FFFFFF"><c:out value="${requestScope.form.name}"></c:out></td>
              <th width="67" class="word_white">性别:</th>
              <td width="171" bgcolor="#FFFFFF"><c:out value="${requestScope.form.sex}" /></td>
            </tr>
运行后,取不到“姓名”和“性别”的值,而是分别显示${requestScope.form.name}、${requestScope.form.sex}请为是什么原因,我该怎么解决,多谢了

解决方案 »

  1.   

    你最好把表单传过来的值放到对象里,在把对象传到后台,你actionForm后面的看不到,不知你是不是把
    actionForm传到了前台
      

  2.   

    value="${<%=requestScope.form.name%>}
    试试!
      

  3.   

    jsp代码:<tr>
        <th width="69" height="30" class="word_white">姓名:</th>
        <td width="166" bgcolor="#FFFFFF"><c:out value="<%=((InviteJobActionFrom)requestScope.form).name%>"></c:out></td>
        <th width="67" class="word_white">性别:</th>
        <td width="171" bgcolor="#FFFFFF"><c:out value="<%=((InviteJobActionFrom)requestScope.form).sex%>" /></td>
    </tr>
    是不是应该先将requestScope.form转换为相应对象啊?
    很久没碰代码了,别笑话!
      

  4.   

    form对象本来就放在请求里面的,不需要你手动设.
    面页怎么不用标签做,用struts标签会直接赋值的.
      

  5.   

    <tr>
                  <th width="69" height="30" class="word_white">姓名:</th>
                  <td width="166" bgcolor="#FFFFFF">${form.name}</td>
                  <th width="67" class="word_white">性别:</th>
                  <td width="171" bgcolor="#FFFFFF">${form.sex}</td>
                </tr>
    这样应该行了
    另外这一句
    InviteJobActionFrom inviteForm=invitejob.getInviteJobById(new Integer(request.getParameter("id")));
    invitejob是属性吧,action里不要放属性,要不会有多线程问题
    自己搜一下
      

  6.   

    贴web.xml看看,用表达式语言,我曾也遇到这个问题,改了一些配置类的信息就可以了,具体忘记哪了.
      

  7.   

    WEB.XML<web-app>
    <display-name>Struts Examples Application</display-name>
    <!-- Standard Action Servlet Configuration (with debugging) -->
    <servlet>
    <servlet-name>action</servlet-name>
    <servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
    <init-param>
    <param-name>config</param-name>
    <param-value>/WEB-INF/struts-config.xml</param-value>
    </init-param> <init-param>
    <param-name>debug</param-name>
    <param-value>2</param-value>
    </init-param>
    <init-param>
    <param-name>detail</param-name>
    <param-value>2</param-value>
    </init-param>
    <load-on-startup>2</load-on-startup>
    </servlet>
    <!-- Standard Action Servlet Mapping -->
    <servlet-mapping>
    <servlet-name>action</servlet-name>
    <url-pattern>*.do</url-pattern>
    </servlet-mapping>
    <!-- Struts Tag Library Descriptors -->
    <taglib>
    <taglib-uri>/tags/struts-bean</taglib-uri>
    <taglib-location>/WEB-INF/struts-bean.tld</taglib-location>
    </taglib> <taglib>
    <taglib-uri>/tags/struts-html</taglib-uri>
    <taglib-location>/WEB-INF/struts-html.tld</taglib-location>
    </taglib> <taglib>
    <taglib-uri>/tags/struts-logic</taglib-uri>
    <taglib-location>/WEB-INF/struts-logic.tld</taglib-location>
    </taglib> <taglib>
    <taglib-uri>/tags/struts-nested</taglib-uri>
    <taglib-location>/WEB-INF/struts-nested.tld</taglib-location>
    </taglib> <taglib>
    <taglib-uri>/tags/struts-tiles</taglib-uri>
    <taglib-location>/WEB-INF/struts-tiles.tld</taglib-location>
    </taglib>
    <!-- ??spring???? -->
    <context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath*:applicationContext-*.xml</param-value> </context-param> <listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener> <filter>
    <filter-name>Spring character encoding filter</filter-name>
    <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
    <init-param>
    <param-name>encoding</param-name>
    <param-value>utf-8</param-value>
    </init-param>
    </filter> <filter-mapping>
    <filter-name>Spring character encoding filter</filter-name>
    <url-pattern>/*</url-pattern>
    </filter-mapping> <filter>
    <filter-name>hibernateFilter</filter-name>
    <filter-class>com.wanglei.hr.tools.OpenSessionInViewFilter</filter-class>
    </filter>
    <filter-mapping>
    <filter-name>hibernateFilter</filter-name>
    <url-pattern>*.do</url-pattern>
    </filter-mapping>
    <init-param>
    <param-name>singleSession </param-name>
    <param-value>true </param-value>
    <param-name> flushMode </param-name>
    <param-value>1 </param-value>
    </init-param></web-app>
      

  8.   

    刚找以前的代码,看到有这样的内容,你参考一下web.xml的头部是:
    <?xml version="1.0" encoding="GBK"?>
    <!--
      Licensed to the Apache Software Foundation (ASF) under one or more
      contributor license agreements.  See the NOTICE file distributed with
      this work for additional information regarding copyright ownership.
      The ASF licenses this file to You under the Apache License, Version 2.0
      (the "License"); you may not use this file except in compliance with
      the License.  You may obtain a copy of the License at      http://www.apache.org/licenses/LICENSE-2.0  Unless required by applicable law or agreed to in writing, software
      distributed under the License is distributed on an "AS IS" BASIS,
      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      See the License for the specific language governing permissions and
      limitations under the License.
    -->
    <web-app xmlns="http://java.sun.com/xml/ns/javaee"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
        version="2.5">注意,jsp2.0才有表达示语言,这里的web-app_2_5.xsd可以是2.4之上的jsp中有一句:<%@ page isELIgnored="false" %>,我页面里显示的写了这一句,按理说是可以不要的.我用的是struts2 ,spring
      

  9.   

    我用的是struts1.x ,在JSP里 没有这个isELIgnored
      

  10.   

    解决了,在JSP中用
    <bean:write name="form" property="name">
    <bean:write name="form" property="sex"/>
    就取到值了
    还是多谢各位的解答
      

  11.   

    呵呵,也可写成
    <bean:write name="form" property="*">
    *是代表全部的意思