首先声明,我是java菜鸟,前两天打算用struts框架做一个简单的登陆界面,但是编译LoginForm.java文件的时候就是通过不了,总是提示找不到符号,下面是这个文件的代码:
/**
*LoginForm.java(这个文件只提供简单的表单验证的功能)
*/
package login;import javax.servlet.http.HttpServletRequest;
import org.apache.struts.action.ActionMesssage;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
/**
* Form bean for the user login page.
*/
public final class LoginForm extends ActionForm {
private String password = null;
private String userName = null; /**
* Public accessors and mutators
*/
public void setUserName(String userName) {
this.userName = userName;
} public String getUserName() {
return (this.userName);
} public String getPassword() {
return (this.password);
} public void setPassword(String password) {
this.password = password;
} /**
* Reset all properties to their default values.
*/
public void reset(ActionMapping mapping,
HttpServletRequest request) {
this.userName = null;
this.password = null;
} /**
* Validate the properties that have been set from this HTTP request,
* and return an <code>ActionErrors</code> object that encapsulates any
* validation errors that have been found. If no errors are found, return
* <code>null</code> or an <code>ActionErrors</code> object with no
* recorded error messages.
*
* @param mapping The mapping used to select this instance
* @param request The servlet request we are processing
*/
public ActionErrors validate(ActionMapping mapping,
HttpServletRequest request) {
ActionErrors errors = new ActionErrors(); if (userName == null || userName.length()< 1)
errors.add("user", new ActionMessage("login.no.username.error"));
if(password==null||password.length()<1)
errors.add("user",new ActionMessage("login.no.password.error"));
return errors;
}
}编译时错误如下:
>javac LoginForm.java
LoginForm.java:4: 找不到符号
符号: 类 ActionMesssage
位置: 软件包 org.apache.struts.action
import org.apache.struts.action.ActionMesssage;
^
LoginForm.java:60: 找不到符号
符号: 类 ActionMessage
位置: 类 login.LoginForm
errors.add("user", new ActionMessage("login.no.username.error"));
^
LoginForm.java:62: 找不到符号
符号: 类 ActionMessage
位置: 类 login.LoginForm
errors.add("user",new ActionMessage("login.no.password.error"));
^
3错误
tomcat安装文件夹的common\lib目录下也已经有了servlet-api.jar和struts.jar包,另外jdk的lib目录里也已经有这两个包了,classpath环境变量也已经追加了这两个的路径(我添加的是tomcat安装文件夹的common\lib目录),可错误仍然存在,就是这个问题搞了两天都搞不定,都快气炸了。哪位大侠帮帮忙呀!
/**
*LoginForm.java(这个文件只提供简单的表单验证的功能)
*/
package login;import javax.servlet.http.HttpServletRequest;
import org.apache.struts.action.ActionMesssage;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
/**
* Form bean for the user login page.
*/
public final class LoginForm extends ActionForm {
private String password = null;
private String userName = null; /**
* Public accessors and mutators
*/
public void setUserName(String userName) {
this.userName = userName;
} public String getUserName() {
return (this.userName);
} public String getPassword() {
return (this.password);
} public void setPassword(String password) {
this.password = password;
} /**
* Reset all properties to their default values.
*/
public void reset(ActionMapping mapping,
HttpServletRequest request) {
this.userName = null;
this.password = null;
} /**
* Validate the properties that have been set from this HTTP request,
* and return an <code>ActionErrors</code> object that encapsulates any
* validation errors that have been found. If no errors are found, return
* <code>null</code> or an <code>ActionErrors</code> object with no
* recorded error messages.
*
* @param mapping The mapping used to select this instance
* @param request The servlet request we are processing
*/
public ActionErrors validate(ActionMapping mapping,
HttpServletRequest request) {
ActionErrors errors = new ActionErrors(); if (userName == null || userName.length()< 1)
errors.add("user", new ActionMessage("login.no.username.error"));
if(password==null||password.length()<1)
errors.add("user",new ActionMessage("login.no.password.error"));
return errors;
}
}编译时错误如下:
>javac LoginForm.java
LoginForm.java:4: 找不到符号
符号: 类 ActionMesssage
位置: 软件包 org.apache.struts.action
import org.apache.struts.action.ActionMesssage;
^
LoginForm.java:60: 找不到符号
符号: 类 ActionMessage
位置: 类 login.LoginForm
errors.add("user", new ActionMessage("login.no.username.error"));
^
LoginForm.java:62: 找不到符号
符号: 类 ActionMessage
位置: 类 login.LoginForm
errors.add("user",new ActionMessage("login.no.password.error"));
^
3错误
tomcat安装文件夹的common\lib目录下也已经有了servlet-api.jar和struts.jar包,另外jdk的lib目录里也已经有这两个包了,classpath环境变量也已经追加了这两个的路径(我添加的是tomcat安装文件夹的common\lib目录),可错误仍然存在,就是这个问题搞了两天都搞不定,都快气炸了。哪位大侠帮帮忙呀!
tomcat的盛放jar的不同位置的类加载器是不同的。
tomcat的盛放jar的不同位置的类加载器是不同的。"Fenglee2008,我应用的WEB-INF/lib下本来就已经有struts.jar包了,3Qs。
类型错了,这个地方是向error中添加,当然应该是Error类型。
我怀疑应该是版本的问题。
记得好像1.1到1.2,1.3变动好像就是在ActionMesssage这里的。
检查一下版本,比较一下1.1的api和1.2的api文档
ActionMessages
而没有ActionMessage这个类
我这没1.1的api文档
因为电脑硬盘空间快没了,都给我清理出去了
其实我很不喜欢Struts,选框架的时候我一般都不会先想到它。
Struts确实是对Model2的一个不错的实现,但并不是在哪里都可以用,用不好反而会适得其反。