我想把hello.jsp提交页面中输入数据后提交到helloAction中,然后再跳转到true.jsp页面中显示刚才输入的数据
hello.jsp代码如下:<%@ page language="java" pageEncoding="GBK"%>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-bean" prefix="bean"%> 
<%@ taglib uri="http://jakarta.apache.org/struts/tags-html" prefix="html"%>
 
<html> 
<head>
<title>JSP for HelloForm form</title>
</head>
<body>
<html:form action="/hello">
userName : <html:text property="userName"/><html:errors property="userName"/><br/>
userPassword : <html:text property="userPassword"/><html:errors property="userPassword"/><br/>
<html:submit/><html:cancel/>
</html:form>
</body>
</html>helloAction中的ActionForward数据为:public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
HelloForm helloForm = (HelloForm) form;// TODO Auto-generated method stub
String name = helloForm.getUserName();
String password = helloForm.getUserPassword();
if((name)==null || (name).length()<1 && (password)==null || (password).length()<1){
return mapping.findForward("HELLO");
}else{
System.out.println("您输入的用户名是:"+name+",用户密码是:"+password);
return mapping.findForward("TRUE");
}
}在这个方法中判断,如果name和password不为空则提交到true.jsp页面,但是就是显示不出来,请各位高手指点啊,谢谢!!struts-config.xml中的数据是:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.1//EN" "http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd"><struts-config>
  <data-sources />
  <form-beans >
    <form-bean name="helloForm" type="com.yourcompany.struts.form.HelloForm" />  </form-beans>  <global-exceptions />
  <global-forwards >
    <forward name="TRUE" path="/form/true.jsp" />  </global-forwards>  <action-mappings >
    <action
      attribute="helloForm"
      input="/form/hello.jsp"
      name="helloForm"
      path="/hello"
      scope="request"
      type="com.yourcompany.struts.action.HelloAction" />  </action-mappings>  <message-resources parameter="com.yourcompany.struts.ApplicationResources" />
</struts-config>请各位高手指点!!!!

解决方案 »

  1.   

    没有异常出现,可以运行,只是我想把取得的数据在true.jsp中显示出来办不到,请指点
      

  2.   

    System.out.println("您输入的用户名是:"+name+",用户密码是:"+password); 
    不能这么写吧把数据放在一个javabean对象里 
    然后request.setAttribute(你那个bean对象)forward到那个页面,可以用struts里标签显示出来楼主了解一下DTO吧
      

  3.   

    在helloAction里
    System.out.println("您输入的用户名是:"+name+",用户密码是:"+password);  
    只会将信息打印到控制台应该request.setAttribute("name",name); 
    request.setAttribute("password",password); 在true.jsp中写
    您输入的用户名是:<%=name%>,用户密码是:<%=password%>
    或者
    System.out.println("您输入的用户名是:"+name+",用户密码是:"+password);  
      

  4.   

    恩 生命周期已经结束了PS:return mapping.findForward("HELLO"); 好象也找不到吧
      

  5.   

    改action如下:
    <action
          attribute="helloForm"
          input="/form/hello.jsp"
          name="helloForm"
          path="/hello"
          scope="request"
          type="com.yourcompany.struts.action.HelloAction"  >
          
          <forward name="TRUE" path="/form/true.jsp" / > 
          <forward name="HELLO" path="/form/hello.jsp" / > 
    </action>global-forwards沒什麼意義,刪掉.
      

  6.   

    提交到helloaction的时候你的数据就已经失效了,你再加句
    request.setAttribute("name",name);  
    request.setAttribute("password",password);  
    再在
     <forward name="TRUE" path="/form/true.jsp" /  >  
     <forward name="HELLO" path="/form/hello.jsp" /  >  
    true.jsp中用,<%=(String)request.getAttribute("name")%>接收
    可能是这样
      

  7.   

    true.jsp页面中没有任何有用的代码,只是起到一个跳转的作用!
     
      

  8.   

    你在hello.jsp中用
    <html:text property="userName"/ > 
    <html:text property="userPassword"/ > 
    两个文本框来保存填入的数据,就说明你在HelloForm中有这两个属性的定义了.
    你在提交hello.jsp后数据被记录在HelloForm中有这两个属性中了.
    在跳到下一个页面之前,HelloForm是有效的.
    在true.jsp的这个页面里找一个地方用
    <bean:write name="helloForm" property="userName" />
    <bean:write name="helloForm" property="userPassword" />
    就可以在这个页面输出了.
      

  9.   

    是生命周期的问题么。存在from里,action传一下,再传到下个页面不行么?
      

  10.   

    我按楼上这么说的去做了,可是还不行啊!你在hello.jsp中用 
    <html:text property="userName"/  >  
    <html:text property="userPassword"/  >  
    两个文本框来保存填入的数据,就说明你在HelloForm中有这两个属性的定义了. 
    你在提交hello.jsp后数据被记录在HelloForm中有这两个属性中了. 
    在跳到下一个页面之前,HelloForm是有效的. 
    在true.jsp的这个页面里找一个地方用 
    <bean:write name="helloForm" property="userName" / > 
    <bean:write name="helloForm" property="userPassword" / > 
    就可以在这个页面输出了.这样不物,true.jsp页面中出错了!
    <bean:write name="helloForm" property="userName" / > 
    <bean:write name="helloForm" property="userPassword" / > 
    这两行的错误提示是:
            Multiple annotations found at this line:
    - Tag bean:write must be empty
    - Missing end tag "bean:write"
    还是不行啊!
      

  11.   

    好了,我已经调试出来了,能够正确的显示数据了,谢谢!在helloAction中的ActionForward方法中写入以下数据:
            request.setAttrabute("name",userName);
            request.setAttrabute("password",userPassword);
    然后在true.jsp页面中写入以下数据就可以了,可以正常的运行出来结果了!
            <%
              String userName = request.getAttrabute("userName");
              String userPassword = request.getAttrabue("userPassword");
              out.println("您输入的用户名是:"+userName+",用户口令是:"+userPassword);
            %>这样写可以完全的把结果输出到true.jsp页面中来!
      

  12.   

    欢迎加入本人的QQ群,群号5586686,身份认证输入如:JAVA、JSP、STRUTS等都可以,非软件开发人员勿加,谢谢合作!