本人想做一个人力资源系统,用ssh做。虽然网上已经有源码了。但部分struts部分还是用的是 struts1.而且我想自己做出来,就算是学习了。但是用struts2做登录功能就出现了问题,问题如下:
1.首先我在jsp页面中代码如下:login.jsp
<div id="center">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>
<s:text name="login.index"></s:text>
<br />
<br />
</td>
</tr>
<tr>
<td>
<s:form id="form1" name="form1" method="post" action="login" theme="simple">
<div>
<s:text name="login.username"></s:text>
<s:textfield name="username" id="textfield"></s:textfield>
</div>
<div>
<s:text name="login.password"></s:text>
<s:password name="password" id="textfield2"></s:password>
</div>
<label>
<s:submit id="button" value="%{getText('login.submit')}"></s:submit>
</label>
</s:form>
</td>
</tr>
<tr>
<td>
<s:actionerror/>
</td>
</tr>
</table>
</div>
2.struts.xml 配置如下:
     <struts>
        <package name="struts2" extends="struts-default">
<action name="login" class="loginAction">
<result name="success" type="dispatcher">/index.jsp</result>
<result name="input">/users/login.jsp</result>
</action>
</package>
</struts>3.action类如下:
     package com.wilsonily.struts2.modeldriven.action;import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
import com.wilsonily.beans.User;@SuppressWarnings( { "serial", "unchecked" })
public class LoginAction extends ActionSupport implements ModelDriven { private User user; public User getUser() {
return user;
} public void setUser(User user) {
this.user = user;
} public String execute() throws Exception {
return SUCCESS;
} public Object getModel() {
return getUser();
} @Override
public void validate() { if (user.getUsername() == null
|| user.getUsername().trim().length() <= 0) { this.addActionError(getText("login.error.username.null"));
} else if (!"wilsonily".equals(user.getUsername())) { this.addActionError(getText("login.error.username.wrong"));
} if (user.getPassword() == null
|| user.getPassword().trim().length() <= 0) { this.addActionError(getText("login.error.password.null"));
} else if (!"wilsonily".equals(user.getPassword())) { this.addActionError(getText("login.error.password.wrong"));
} }}4. 由于我使用是spring自动装配实例:applicationContext.xml :
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
        http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context-3.0.xsd">
        
<bean id="loginAction" class="com.wilsonily.struts2.modeldriven.action.LoginAction" scope="prototype">
<property name="user" ref="user"></property>
</bean>
</beans>
<bean id="user" class="com.wilsonily.beans.User">
</bean> 5.由于我使用的是struts.properties,配置struts相关的参数:
        struts.i18n.encoding=utf-8
struts.custom.i18n.resources=com.wilsonily.resource.messageResource,com.wilsonily.resource.errorMessage
struts.i18n.reload=true
struts.configuration.xml.reload=true
struts.serve.static.browserCache=false
struts.devMode=true6.错误信息使用的也是国际化的:errorMessage.properties :
login.error.username.null=username should be inputted,please input.
login.error.username.wrong=username is wrong,please input again.
login.error.password.null=password should be inputted,please input.
login.error.password.wrong=password is wrong,please input again.7.现在的问题是:
当我在login.jsp 页面中输入错误的用户名,错误信息是能够显示出来,第一次能完全没有问题的显示,但是当第二次开始,我输入错误信息提交的是,返回给我的jsp页面和原来的完全不同,原来在界面中的图片,样式什么的全没有了。就只剩下最基本的html页面,请问这是怎么回事?高手请上来解决一下:不胜感激!