把你的struts-config.xml及你的action粘上来看看 这样不太好判断
解决方案 »
- 关于 spring 注入构造函数含有具体映射的Bean
- 服务器端的文件权限控制问题
- 【急求】修改XML节点值
- 數據庫中字符型數字串,都變成了同一個 負數串-125860,有誰遇到過類似的問題碼?
- 我有疑问啊,ForwardAction类是不是只应用在<html:form>的action中,是不是啊?
- Hibernate的JTA事务管理是不是一定要在应用程序服务器中才可以用?如果单独可以用,怎么配置配置文件?
- 数学公式的求解!
- JBuilderX+WebSphere5.1下如在JBuilder中启动WebSphere Server
- 请教struts中logic:iterate问题
- 请教大家一个莫名其妙的问题
- xpath中position函数的问题,高手帮忙看看错在哪里
- struts is easy
以下是我的一些配置及代码:
(1)struts-config.xml
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE struts-config PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 1.2//EN"
"http://struts.apache.org/dtds/struts-config_1_2.dtd">
<struts-config>
<form-beans>
<form-bean name="loginForm" type="net.vshow.maintain.form.LoginForm"/>
</form-beans>
<action-mappings>
<action name="loginForm" type="net.vshow.maintain.action.LoginAction" validate="true" input="/index.jsp" scope="request" path="/login">
<forward name="loginFailed" path="/index.jsp" />
<forward name="loginSuccess" path="/index.jsp" />
</action>
</action-mappings> <message-resources parameter="net.vshow.maintain.resources.application" /> <plug-in className="org.apache.struts.validator.ValidatorPlugIn">
<set-property property="pathnames" value="/WEB-INF/validator-rules.xml,/WEB-INF/validation.xml" />
<set-property property="stopOnFirstError" value="true" />
</plug-in>
</struts-config>(2)validation.xml
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE form-validation PUBLIC
"-//Apache Software Foundation//DTD Commons Validator Rules Configuration 1.1.3//EN"
"http://jakarta.apache.org/commons/dtds/validator_1_1_3.dtd"><form-validation>
<global>
<constant>
<constant-name>phone</constant-name>
<constant-value>^\(?(\d{3})\)?[-| ]?(\d{3})[-| ]?(\d{4})$</constant-value>
</constant>
</global> <formset>
<form name="loginForm">
<field property="account"
depends="required">
<msg name="required"
key="errors.required"/>
<arg0 key="user.account"/>
</field>
<field property="password"
depends="required">
<arg0 key="user.password"/>
</field>
</form>
</formset>
</form-validation>(3)LoginForm.java
public class LoginForm extends ValidatorForm{ private String account=null;
private String password=null;
........
}(4)LoginAction.java
public class LoginAction extends Action
{ public ActionForward execute(ActionMapping actionmapping, ActionForm actionform,
HttpServletRequest httpservletrequest, HttpServletResponse httpservletresponse)
{
LoginForm form = (LoginForm)actionform;
Maintainer maintainer=DatabaseUtils.getMaintainer(form.getAccount(),form.getPassword());
if(maintainer != null)
{
HttpSession httpsession = httpservletrequest.getSession(false);
if(httpsession != null)
httpsession.removeAttribute("Maintainer");
else
httpsession = httpservletrequest.getSession(true);
httpsession.setAttribute("Maintainer", maintainer);
return actionmapping.findForward("loginSuccess");
}
return actionmapping.findForward("loginFailed");
}
}