浏览 2164 次
锁定老帖子 主题:求助!页面传值的问题
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
|
|
---|---|
作者 | 正文 |
发表时间:2007-04-11
JSP页面: <%@ page language="java"%> <%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %> <%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %> <%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %> <html> <head> <title>JSP for SpringForm form</title> </head> <body> <form name="login" action="<%=request.getContextPath()%>/spring.do?method=login"> <table> <tr><td>usename:<input name="name" type="text"></td></tr> <tr><td>password:<input name="password" type="password"></td></tr> <tr><td><input name="submit" type="submit" value="submit"></td></tr> </table> </form> </body> </html> ---------------------------------------------------- springForm中的代码: /* * Generated by MyEclipse Struts * Template path: templates/java/JavaClass.vtl */ package com.yourcompany.struts.form; import javax.servlet.http.HttpServletRequest; import org.apache.struts.action.ActionErrors; import org.apache.struts.action.ActionForm; import org.apache.struts.action.ActionMapping; import org.apache.struts.action.ActionMessage; /** * MyEclipse Struts * Creation date: 04-11-2007 * * XDoclet definition: * @struts.form name="springForm" */ public class SpringForm extends ActionForm { /* * Generated fields */ /** password property */ private String password; /** name property */ private String name; /* * Generated Methods */ /** * Method validate * @param mapping * @param request * @return ActionErrors */ public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) { ActionErrors error = new ActionErrors(); if((name == null) || (name.length() < 1)) System.out.println(name); System.out.println(password); System.out.println("running!"); System.out.println(request.getAttribute(name)); System.out.println("out!"); error.add("name", new ActionMessage("no.usename")); if ((password == null) || (password.length() < 1)) error.add("password", new ActionMessage("no.password")); // TODO Auto-generated method stub return error; } /** * Method reset * @param mapping * @param request */ public void reset(ActionMapping mapping, HttpServletRequest request) { // TODO Auto-generated method stub } /** * Returns the password. * @return String */ public String getPassword() { return password; } /** * Set the password. * @param password The password to set */ public void setPassword(String password) { this.password = password; } /** * Returns the name. * @return String */ public String getName() { return name; } /** * Set the name. * @param name The name to set */ public void setName(String name) { this.name = name; } } -------------------------------------- struts中的配置 <action attribute="springForm" input="/spring.jsp" name="springForm" path="/spring" parameter="method" scope="request" type="org.springframework.web.struts.DelegatingActionProxy"> <forward name="hello" path="/hello.jsp" /> <forward name="error" path="/spring.jsp" /> </action> ----------------------------- 后台输出的结果: zhao running! null out! 为什么requset对象中的值是null,JSP页面哪里出错了? 声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
推荐链接
|
|
返回顶楼 | |
发表时间:2007-04-11
方块石 写道 在JSP页面中,表单为什么只传了password的值过去了?而name的值没有。不知道jsp页面这样写有什么问题,谢谢了。
用from,get取值呀
JSP页面: <%@ page language="java"%> <%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %> <%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %> <%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %> <html> <head> <title>JSP for SpringForm form</title> </head> <body> <form name="login" action="<%=request.getContextPath()%>/spring.do?method=login"> <table> <tr><td>usename:<input name="name" type="text"></td></tr> <tr><td>password:<input name="password" type="password"></td></tr> <tr><td><input name="submit" type="submit" value="submit"></td></tr> </table> </form> </body> </html> ---------------------------------------------------- springForm中的代码: /* * Generated by MyEclipse Struts * Template path: templates/java/JavaClass.vtl */ package com.yourcompany.struts.form; import javax.servlet.http.HttpServletRequest; import org.apache.struts.action.ActionErrors; import org.apache.struts.action.ActionForm; import org.apache.struts.action.ActionMapping; import org.apache.struts.action.ActionMessage; /** * MyEclipse Struts * Creation date: 04-11-2007 * * XDoclet definition: * @struts.form name="springForm" */ public class SpringForm extends ActionForm { /* * Generated fields */ /** password property */ private String password; /** name property */ private String name; /* * Generated Methods */ /** * Method validate * @param mapping * @param request * @return ActionErrors */ public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) { ActionErrors error = new ActionErrors(); if((name == null) || (name.length() < 1)) System.out.println(name); System.out.println(password); System.out.println("running!"); System.out.println(request.getAttribute(name)); System.out.println("out!"); error.add("name", new ActionMessage("no.usename")); if ((password == null) || (password.length() < 1)) error.add("password", new ActionMessage("no.password")); // TODO Auto-generated method stub return error; } /** * Method reset * @param mapping * @param request */ public void reset(ActionMapping mapping, HttpServletRequest request) { // TODO Auto-generated method stub } /** * Returns the password. * @return String */ public String getPassword() { return password; } /** * Set the password. * @param password The password to set */ public void setPassword(String password) { this.password = password; } /** * Returns the name. * @return String */ public String getName() { return name; } /** * Set the name. * @param name The name to set */ public void setName(String name) { this.name = name; } } -------------------------------------- struts中的配置 <action attribute="springForm" input="/spring.jsp" name="springForm" path="/spring" parameter="method" scope="request" type="org.springframework.web.struts.DelegatingActionProxy"> <forward name="hello" path="/hello.jsp" /> <forward name="error" path="/spring.jsp" /> </action> ----------------------------- 后台输出的结果: zhao running! null out! 为什么requset对象中的值是null,JSP页面哪里出错了? |
|
返回顶楼 | |