100分新手做struts出现的问题 所有代码都已贴出 请高手指点!!

lijiashu1981 2005-03-08 09:34:19
错误提示如下:
Error page jsp1

An error occured in the bean. Error Message is: org/apache/struts/action/ActionForm
Stack Trace is :
java.lang.NoClassDefFoundError: org/apache/struts/action/ActionForm
at java.lang.ClassLoader.defineClass0(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:502)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:123)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:250)
at java.net.URLClassLoader.access$100(URLClassLoader.java:54)
at java.net.URLClassLoader$1.run(URLClassLoader.java:193)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:186)
at java.lang.ClassLoader.loadClass(ClassLoader.java:299)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:272)
at java.lang.ClassLoader.loadClass(ClassLoader.java:292)
at java.lang.ClassLoader.loadClass(ClassLoader.java:292)
at java.lang.ClassLoader.loadClass(ClassLoader.java:292)
at java.lang.ClassLoader.loadClass(ClassLoader.java:255)
at weblogic.utils.classloaders.GenericClassLoader.loadClass(GenericClassLoader.java:223)
at weblogic.utils.classloaders.ChangeAwareClassLoader.loadClass(ChangeAwareClassLoader.java:41)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:315)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:140)
at org.apache.struts.taglib.html.FormTag.doStartTag(FormTag.java:563)
at jsp_servlet.__jsp1._jspService(__jsp1.java:198)
at weblogic.servlet.jsp.JspBase.service(JspBase.java:33)
at weblogic.servlet.internal.ServletStubImpl$ServletInvocationAction.run(ServletStubImpl.java:971)
at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:402)
at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:305)
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:6350)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:317)
at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:118)
at weblogic.servlet.internal.WebAppServletContext.invokeServlet(WebAppServletContext.java:3635)
at weblogic.servlet.internal.ServletRequestImpl.execute(ServletRequestImpl.java:2585)
at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:197)
at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:170)



jsp1.jsp代码如下:

<%@ page contentType="text/html; charset=GBK" %>
<%@ page errorPage="jsp1_error.jsp" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/struts-template.tld" prefix="template" %>
<html:html locale="true">
<head>
<html:base/>
<title>
第一个struts登陆窗口

</title>
</head>
<body>
<h2>请输入用户名和密码</h2>
<html:form action="loginaciton.do" >
userName:<html:text property="userName"/><br/>
userPassword:<html:password property="userPassword"/><br/>
userLoginname:<html:text property="userLoginname"/><br/>
<html:submit property="submit"/>
</html:form>
</body>
<bean:message key="aaa"/>
</html:html>

loginbean代码如下:
package struts.loginbean;



public class Loginbean {

public String userName;
public String userPassword;
public String userLoginname;

public void login(String name,String pass)
{
name = pass;
pass = name;
}

public String getLoginName() {
return userLoginname;
}

public void setLoginName(String loginName) {
this.userLoginname = loginName;
}

public void setPassWord(String passWord) {
this.userPassword = passWord;
}

public String getPassWord() {
return userPassword;
}

public String getUserName() {
return userName;
}

public void setUserName(String userName) {
this.userName = userName;
}

}

loginform代码如下:


package struts.formbean;

import struts.loginbean.*;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionError;

public class Loginform extends ActionForm {

//private String userName;
//private String userPassword;
//private String userLoginname;

private Loginbean loginbean = new Loginbean();

public void setUserName(String userName)
{
loginbean.setUserName(userName);
}
public String getUserName()
{
return loginbean.getUserName();
}
public void setPassWord(String userPassword)
{
loginbean.setPassWord(userPassword);
}
public String getPassWord()
{
return loginbean.getPassWord();
}
public void setLoginName(String userLoginname)
{
loginbean.setLoginName(userLoginname);
}
public String getLoginName()
{
return loginbean.getLoginName();
}

public ActionErrors validate(ActionMapping actionMapping,
HttpServletRequest httpServletRequest) {
ActionErrors errors = new ActionErrors();
if((loginbean.getLoginName()==null))
{
errors.add("userPassword",new ActionError("error.loginbean.userPassword"));
}
/**@todo: finish this method, this is just the skeleton.*/
return errors;
}

public void reset(ActionMapping actionMapping,
HttpServletRequest httpServletRequest) {
this.loginbean = new Loginbean();
}
}


loginaction代码如下:

package struts.action;
import struts.loginbean.*;
import struts.formbean.*;
import org.apache.struts.action.*;
import javax.servlet.http.*;


public class loginaciton extends Action {
public ActionForward perform(ActionMapping actionMapping, ActionForm actionForm, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) {
/**@todo: complete the business logic here, this is just a skeleton.*/

Loginform loginform = (Loginform) actionForm;
try
{
Loginbean bean = new Loginbean();
bean.login(loginform.getLoginName(),loginform.getPassWord());

}
catch(Exception e)
{
e.printStackTrace();
}

return (actionMapping.findForward("loginaciton33"));
// throw new java.lang.UnsupportedOperationException("Method perform() not yet implemented.");
}
}

struts-config.xml如下:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.0//EN" "http://jakarta.apache.org/struts/dtds/struts-config_1_0.dtd">
<struts-config>
<form-beans>
<form-bean name="loginform" type="struts.formbean.Loginform" />
</form-beans>
<global-forwards>
<forward name="loginaciton33" path="/jsp2.jsp" />
</global-forwards>
<action-mappings>
<action name="loginform" path="/loginaciton" scope="request" type="struts.action.loginaciton" />
</action-mappings>
<message-resources parameter="struts.ApplicationResources" />
</struts-config>
...全文
155 点赞 收藏 20
写回复
20 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
feelsmall 2005-03-09
试着重新生成一下工程,只要框架,不写内容,最好区分一下类的小小写。
回复
lijiashu1981 2005-03-08
上面的二位老大别着急走 再多看我帖子几眼哦
回复
lijiashu1981 2005-03-08
我的struts-config.xml应该没有什么错误吧?
回复
lijiashu1981 2005-03-08
设置环境变量后出先错误


Error page jsp1 An error occured in the bean. Error Message is: Cannot find ActionMappings or ActionFormBeans collectionStack Trace is : javax.servlet.jsp.JspException: Cannot find ActionMappings or ActionFormBeans collection
at org.apache.struts.taglib.html.FormTag.lookup(FormTag.java:798)
at org.apache.struts.taglib.html.FormTag.doStartTag(FormTag.java:506)
at jsp_servlet.__jsp1._jspService(__jsp1.java:198)
at weblogic.servlet.jsp.JspBase.service(JspBase.java:33)
at weblogic.servlet.internal.ServletStubImpl$ServletInvocationAction.run(ServletStubImpl.java:971)
at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:402)
at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:446)
at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:305)
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:6350)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:317)
at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:118)
at weblogic.servlet.internal.WebAppServletContext.invokeServlet(WebAppServletContext.java:3635)
at weblogic.servlet.internal.ServletRequestImpl.execute(ServletRequestImpl.java:2585)
at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:197)
at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:170)

回复
JustinGr 2005-03-08
当然需要啦 很有可能就是你没有设置好环境变量 TRY AGAIN!
回复
lijiashu1981 2005-03-08
我用的jbx和weblogic 还需要配置系统的环境变量吗?
回复
java.lang.NoClassDefFoundError: org/apache/struts/action/ActionForm
应该是找不到struts的类文件,你需要将struts.jar添加到classpath中
回复
lijiashu1981 2005-03-08
自己先顶一下 在线等 进来看的XD帮我顶顶 我弄了两天了
回复
zeq258 2005-03-08
问题一: <html:base/> 可以不要!
问题二: <bean:message key="aaa"/>你既然要引用messages而且名字是aaa,
那么你的<message-resources parameter="struts.ApplicationResources" />
就不对,要一致!
改法一:<message-resources parameter="aaa" />
当然你的文件的名字也要改!
改法二:<bean:message key="文件名(不需要后缀)"/>
回复
zeq258 2005-03-08
49137296
回复
lijiashu1981 2005-03-08
有QQ吗 在QQ上问能及时一些
回复
lijiashu1981 2005-03-08
再看看 这回我写的没毛病了吧?都是用jb自己生成的。看着好象挺多,但无非就是xml、jsp、action、form

1。loginaction.java代码如下

package struts.loginbean;

import struts.formbean.*;
import org.apache.struts.action.*;
import javax.servlet.http.*;
import struts.formbean.Loginform;

public class loginaction extends Action {
public ActionForward perform(ActionMapping actionMapping, ActionForm actionForm, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) {
/**@todo: complete the business logic here, this is just a skeleton.*/
Loginform loginform = (Loginform) actionForm;
throw new java.lang.UnsupportedOperationException("Method perform() not yet implemented.");
}
}

这个是form的

package struts.formbean;

import org.apache.struts.action.*;
import javax.servlet.http.*;

public class Loginform extends ActionForm {
private String userLoginname;
private String userName;
private String userPassword;

public String getUserLoginname() {
return userLoginname;
}
public void setUserLoginname(String userLoginname) {
this.userLoginname = userLoginname;
}
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public String getUserPassword() {
return userPassword;
}
public void setUserPassword(String userPassword) {
this.userPassword = userPassword;
}
public ActionErrors validate(ActionMapping actionMapping, HttpServletRequest httpServletRequest) {
/**@todo: finish this method, this is just the skeleton.*/
return null;
}
public void reset(ActionMapping actionMapping, HttpServletRequest httpServletRequest) {
userLoginname = null;
userName = null;
userPassword = null;
}
}



前面的jsp页面

<%@ page contentType="text/html; charset=GBK" %>
<%--<%@ page errorPage="jsp1_error.jsp" %>--%>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/struts-template.tld" prefix="template" %>
<html:html locale="true">
<head>
<html:base/>
<title>
第一个struts登陆窗口

</title>
</head>
<body>
<h2>请输入用户名和密码</h2>
<html:form action="loginaciton.do" method="post" >
userName:<html:text property="userName"/><br/>
userPassword:<html:password property="userPassword"/><br/>
userLoginname:<html:text property="userLoginname"/><br/>
<html:submit property="submit"/>
</html:form>
</body>
<bean:message key="aaa"/>
</html:html>


最后是配置文件

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.0//EN" "http://jakarta.apache.org/struts/dtds/struts-config_1_0.dtd">
<struts-config>
<form-beans>
<form-bean name="loginform" type="struts.formbean.loginform" />
</form-beans>
<global-forwards>
<forward name="loginaciton33" path="/jsp2.jsp" />
</global-forwards>
<action-mappings>
<action input="/jsp1.jsp" name="loginform" path="/loginaction" scope="request" type="struts.loginbean.loginaction" validate="true" />
</action-mappings>
<message-resources parameter="struts.ApplicationResources" />
</struts-config>
回复
zeq258 2005-03-08
不客气,大家可以互相学习的吗!
回复
lijiashu1981 2005-03-08
我用jb做的 那些变量都存在的 否则jb也会提示俺的

我再试试看 吧 谢谢楼上的
回复
zeq258 2005-03-08
很简单的说一下!
如果你要使用 setName()方法,
那么你就必须声明name变量!

你不可能对一个不存在的变量进行操作!
明白吗?
回复
lijiashu1981 2005-03-08
嘿嘿 谢谢楼上的 俺会打好基础的 不过刚刚看点资料 想上手试试就着急做了

上面你说的那几个问题呢

1。原来我加了post或者get都用了 不好使
2。我只是随便弄个方法放到bean里面留着以后写个过程
3。那个名字一定要对应上吗?
我现在只想能进到页面中去,具体的业务逻辑先不写,目前连页面都显示不出来
错误代码你们也看到了 郁闷ing!!
回复
zeq258 2005-03-08
说的有些绝对了,你的代码我没有看完,
但是问题很多,即使你把struts配置好了,
这个程序本身也不可能运行,!
还是那句话,把基础打好!
回复
zeq258 2005-03-08
问题:
1。 <html:form action="loginaciton.do" > 里边应该有method="post/get"
2。 public class Loginbean {

public String userName;
public String userPassword;
public String userLoginname;

public void login(String name,String pass)
{
name = pass;
pass = name;
}
你定义的变量为 userName;,,,,
可是你的应用中的name 是怎么出来的呢!
3。 public String getLoginName() {
return userLoginname;
}
应该是 public String getUserLoginname()
4.........
5。。。。。
问题太多了!

你出现的这些都不是struts 的问题!
我建议你先不要急着学习struts,把java,jsp的基础打好先!
以上的问题都是java 最基本的变量问题啊!
这样说,你不会介意吧!
回复
code2code 2005-03-08
我也出这个问题 等待中………………
回复
code2code 2005-03-08
我也出这个问题 等待中………………
回复
发帖
Java EE
创建于2007-09-28

6.6w+

社区成员

J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
申请成为版主
帖子事件
创建了帖子
2005-03-08 09:34
社区公告
暂无公告