web.xml内容
<filter>
<filter-name>struts2</filter-name>
<filter-class> org.apache.struts2.dispatcher.FilterDispatcher </filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
java 代码
import com.opensymphony.xwork2.ActionSupport;
public class LoginAction extends ActionSupport{
private String userName;
private String password;
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String execute() throws Exception{
return "success";
}
@Override
public void validate() {
if(this.getUserName() == null || "".equals(this.getUserName().trim())){
this.addFieldError("userName", "输入用户名");
}
if(this.getPassword() == null || "".equals(this.getPassword().trim())){
this.addFieldError("password", "输入密码");
}
}
}
struts.xml内容:
<package name="struts2" extends="struts-default">
<action name="login" class="com.scy.paylist.login.LoginAction">
<result name="success">/pay_list.jsp</result>
<result name="input">/login2.jsp</result>
</action>
</package>
------解决方案--------------------
你的代码我没找到错,可能是你的包引的不对,这个要看你的struts的版本了。如果是最新版的struts的话,你要在webContent的lib下放了类库了么?
放了哪些?加载的是哪些?
我以前少加了一个javassist-3.11.0.GA.jar就会有这个错。
要加的有:
javassist-3.11.0.GA.jar
commons-fileupload-1.2.2.jar
commons-io-2.0.1.jar
commons-lang-2.5.jar
commons-logging-1.1.1.jar
freemarker-2.3.16.jar
ognl-3.0.1.jar
spring-test-2.5.6.jar
struts2-core-2.2.3.1.jar
xwork-core-2.2.3.1.jar
------解决方案--------------------
你用的那个版本的struts2,不同的版本<filter-class> org.apache.struts2.dispatcher.FilterDispatcher </filter-class>中间的内容部太一样
------解决方案--------------------
你在struts2-core-2.2.3.1.jar文件里查查FilterDispatcher这个类的包名,
我的是org.apache.struts2.dispatcher.ng.filter.FilterDispatcher
当然你得把需要的jar文件放到lib目录下咯!