是不是jsp里的标签有问题啊?
<%@ page language="java" pageEncoding="ISO-8859-1"%><%@ taglib uri="http://jakarta.apache.org/struts/tags-bean" prefix="bean" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-html" prefix="html" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-logic" prefix="logic" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-tiles" prefix="tiles" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-template" prefix="template" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-nested" prefix="nested" %><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html:html locale="true">
<head>
<html:base />
<title>userLoginSuccess.jsp</title> <meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
--> </head>
<body>
This a struts page. <br>Hello <bean:write name="userName" scope="request" />
</body>
</html:html>
<%@ page language="java" pageEncoding="ISO-8859-1"%><%@ taglib uri="http://jakarta.apache.org/struts/tags-bean" prefix="bean" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-html" prefix="html" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-logic" prefix="logic" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-tiles" prefix="tiles" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-template" prefix="template" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-nested" prefix="nested" %><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html:html locale="true">
<head>
<html:base />
<title>userLoginSuccess.jsp</title> <meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
--> </head>
<body>
This a struts page. <br>Hello <bean:write name="userName" scope="request" />
</body>
</html:html>
把你的<bean:write name="userName" scope="request" />
userName换成你的form(bean)的名字试试。
HttpServletRequest request, HttpServletResponse response) {
UserLoginForm userLoginForm = (UserLoginForm) form;// TODO Auto-generated method stub
if(userLoginForm.getUserName().equals("abcd")&&userLoginForm.getPassWord().equals("abcd")){
request.setAttribute("userName", userLoginForm.getUserName());
System.out.println("username:" + userLoginForm.getUserName() + "passWord:" +userLoginForm.getPassWord());
return mapping.findForward("success");
}else{
return mapping.findForward("error");
}
}
}
难道我存的不对?
requuest.setAttribute("userName","一个值");
这句话。
如果直接访问这个页面 要先判断 userName 是否为空。
你的userName是个字段,而不是你的formbean
改成:
<bean:write property="userName" scope="request" />
因为name一般代表ActionForm
userName属性应该放入他对应的bean中,再将bean放入request中
这样应该可以得到了
* 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;/**
* MyEclipse Struts
* Creation date: 05-28-2008
*
* XDoclet definition:
* @struts.form name="userLoginForm"
*/
public class UserLoginForm extends ActionForm {
/*
* Generated fields
*/ /** userName property */
private String userName; /** passWord property */
private String passWord; /*
* Generated Methods
*/ /**
* Method validate
* @param mapping
* @param request
* @return ActionErrors
*/
public ActionErrors validate(ActionMapping mapping,
HttpServletRequest request) {
// TODO Auto-generated method stub
return null;
} /**
* Method reset
* @param mapping
* @param request
*/
public void reset(ActionMapping mapping, HttpServletRequest request) {
// TODO Auto-generated method stub
} /**
* Returns the userName.
* @return String
*/
public String getUserName() {
return userName;
} /**
* Set the userName.
* @param userName The userName to set
*/
public void setUserName(String userName) {
this.userName = userName;
} /**
* 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;
}
}
自动生成的应该没什么问题把