我想把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>请各位高手指点!!!!
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>请各位高手指点!!!!
不能这么写吧把数据放在一个javabean对象里
然后request.setAttribute(你那个bean对象)forward到那个页面,可以用struts里标签显示出来楼主了解一下DTO吧
System.out.println("您输入的用户名是:"+name+",用户密码是:"+password);
只会将信息打印到控制台应该request.setAttribute("name",name);
request.setAttribute("password",password); 在true.jsp中写
您输入的用户名是:<%=name%>,用户密码是:<%=password%>
或者
System.out.println("您输入的用户名是:"+name+",用户密码是:"+password);
<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沒什麼意義,刪掉.
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")%>接收
可能是这样
<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" />
就可以在这个页面输出了.
<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"
还是不行啊!
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页面中来!