ActionForm源码package com.xj.guestbook.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;public class LoginForm extends ActionForm {
private static final long serialVersionUID = 1L;
private String url;
private String password;
private String userName; public ActionErrors validate(
ActionMapping mapping,
HttpServletRequest request) {
ActionErrors errors = new ActionErrors();
if (userName == null || userName.length() <= 0) {
errors.add("userNameError", new ActionMessage("error.name.null"));
} else if (userName.length() <= 2) {
errors.add("userNameError", new ActionMessage("error.name.small"));
} if (password == null || password.length() <= 0) {
errors.add("passwordError", new ActionMessage(
"error.password.null"));
} else if (password.length() <= 5) {
errors.add("passwordError", new ActionMessage(
"error.password.small"));
} return errors;
}
public void reset(ActionMapping mapping, HttpServletRequest request) {
this.userName=null;
this.password=null;
this.url=null;
} public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public void setUrl(String url) {
this.url = url;
}
public String getUrl() {
return this.url;
}
}
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;public class LoginForm extends ActionForm {
private static final long serialVersionUID = 1L;
private String url;
private String password;
private String userName; public ActionErrors validate(
ActionMapping mapping,
HttpServletRequest request) {
ActionErrors errors = new ActionErrors();
if (userName == null || userName.length() <= 0) {
errors.add("userNameError", new ActionMessage("error.name.null"));
} else if (userName.length() <= 2) {
errors.add("userNameError", new ActionMessage("error.name.small"));
} if (password == null || password.length() <= 0) {
errors.add("passwordError", new ActionMessage(
"error.password.null"));
} else if (password.length() <= 5) {
errors.add("passwordError", new ActionMessage(
"error.password.small"));
} return errors;
}
public void reset(ActionMapping mapping, HttpServletRequest request) {
this.userName=null;
this.password=null;
this.url=null;
} public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public void setUrl(String url) {
this.url = url;
}
public String getUrl() {
return this.url;
}
}
解决方案 »
- 如何用HttpUrlConnecton进行post的提交?
- [aop问题]为什么在action里无法注入DAO
- 有什么工具可以把html文件转换为xsl文件~~
- petshop对学JAVA和jsp有用没
- 关于tomcat5.0启动后无法停止问题
- javacc,ant,commons-collections,log4j,junit-E 这都什么东西啊?
- spring初学者的第一例子!工厂实例话的问题
- java UDP发送数据用不用多线程?
- redhat8.0+weblogic8.0+oracle9i插入数据库时,中文是乱码,该如何处理?
- poi数据导出excel 我才500条就好慢,大神能看看吗
- TOMCAT4.1下配置JNDI数据源的问题
- hibernateSynchronizer3的配置问题,谢谢!
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;import org.apache.struts.action.Action;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;import com.xj.guestbook.Constants.Constants;
import com.xj.guestbook.dao.UserInfoDAOImpl;
import com.xj.guestbook.form.LoginForm;
import com.xj.guestbook.po.UserInfoPo;
import com.xj.guestbook.vo.UserInfoVo;public class LoginAction extends Action { public ActionForward execute(
ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response) throws Exception{
String userName =(String)((LoginForm) form).getUserName();
String password = (String)((LoginForm) form).getPassword();
UserInfoDAOImpl user=new UserInfoDAOImpl();
UserInfoPo userInfo=user.Check(userName,password);
if(userInfo==null){
ActionErrors errors = new ActionErrors();
errors.add("userNameError", new ActionMessage(
"error.namepassword"));
saveErrors(request, errors); return mapping.getInputForward();
}
//HttpSession session=request.getHttpSession();
request.setAttribute("userInfo",userInfo);
return mapping.findForward(Constants.INDEX_KEY);
}}
<action path="/login"
type="com.xj.guestbook.action.LoginAction"
name="LoginForm"
scope="request"
validate="true"
input="/login.jsp">
</action>
</action-mappings>
<form-bean name="LoginForm" type="com.xj.guestbook.form.LoginForm" />
</form-beans>
<%@ taglib prefix="bean" uri="/WEB-INF/struts-bean.tld"%>
<%@ taglib prefix="html" uri="/WEB-INF/struts-html.tld"%>
<html>
<head>
<title>
<bean:message key="label.title" />
</title> <STYLE TYPE='text/css'>
TD {table-layout :fixed; word-break :break-all}
input.smallInput{border:1 solid black; border-bottom-color:#333399; FONT-SIZE: 9pt; FONT-STYLE: normal; FONT-VARIANT: normal; FONT-WEIGHT: normal; HEIGHT: 18px; LINE-HEIGHT: normal}
input.buttonface{
border:1 solid #ff6633;
COLOR: #FFFFFF;
FONT-SIZE: 9pt;
FONT-STYLE: normal;
FONT-VARIANT: normal;
FONT-WEIGHT: normal;
HEIGHT: 18px;
LINE-HEIGHT: normal;
background: #333399;
}
</STYLE>
</head> <body>
<TABLE width="760" height="4" border="0" align="center">
<TR>
<TD height="1" colspan="3" align="center"">
<%@include file="include/header.jsp"%>
</TD>
</TR>
<TR>
<TD height="1" colspan="3" align="right">
</TD>
</TR>
<tr>
<td>
<html:form action="/login.do" method="post">
<table width="550" border="0" align="center" bgcolor="#EEEEEE">
<tr>
<td height="21" align="center" colspan="2" bgcolor="#3A6EA5">
<FONT size="2" color="#FFFFFF">
<b>
<bean:message key="label.login"/>
</b>
</FONT>
</td>
</tr>
<tr>
<td align="center" colspan="2">
<font size="2">
<br>
<bean:message key="label.login.register1"/>
<bean:message key="label.login.register2"/>
</font>
</td>
</tr>
<tr>
<td width="40%" align="right">
<font size="2">
<b>
<bean:message key="label.username"/>:
</b>
</font>
</td>
<td>
<html:text property="userName" maxlength="17" styleClass="smallInput"/>
<FONT size="2" color="red">
<b>
<html:errors bundle="ERROR_RESOURCES" property="userNameError"/>
</b>
</FONT>
</td>
</tr>
<tr>
<td width="40%" align="right">
<FONT size="2">
<b>
<bean:message key="label.password"/>:
</b>
</FONT>
</td>
<td>
<html:password property="password" maxlength="17" size="20" styleClass="smallInput"/>
<FONT siae="2" color="red">
<b>
<html:errors bundle="ERROR_RESOURCES" property="passwordError"/>
</b>
</FONT>
</td>
</tr>
<tr>
<td colspan="2">
<html:submit styleClass="buttonface">
<bean:message key="label.login"/>
</html:submit>
</td>
</tr>
</table>
</html:form>
</td>
</TR>
<TR>
<TD height="1" colspan="3" align="center">
<%@include file="include/footer.jsp"%>
</TD>
</TR>
</TABLE>
</body>
</html>
<action-mappings>
<action attribute="LoginForm" input="/login.jsp" name="LoginForm" path="/login" type="com.xj.guestbook.action.LoginAction">
<forward name="..." path="....." />
</action>
</action-mappings>
<html:text property="userName" name= "LoginForm" maxlength="17" styleClass="smallInput"/>
你写了吗?
在你的配置文件都没看到这个呢
<!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="LoginForm" type="com.xj.guestbook.form.LoginForm" />
</form-beans>
<global-exceptions />
<global-forwards>
<forward name="index" path="/index.jsp" redirect="true" />
<forward name="login" path="/login.jsp" redirect="true" />
</global-forwards>
<action-mappings >
<action attribute="LoginForm" input="/login.jsp" name="LoginForm" path="/login" type="com.xj.guestbook.action.LoginAction"/>
</action-mappings>
<message-resources parameter="com.xj.guestbook.MessageResources" />
<message-resources key="IMAGE_RESOURCES" parameter="com.xj.guestbook.ImageResources" />
<message-resources key="ERROR_RESOURCES" parameter="com.xj.guestbook.ErrorMessageResources" /></struts-config>
1、这个是什么?
Constants.INDEX_KEY2、path="/login.jsp" 的路径对不对?
ActionErrors errors = new ActionErrors();
errors.add("userNameError", new ActionMessage(
"error.namepassword"));
saveErrors(request, errors);
这里的问题我换了一个struts.jar包就可了