struts入门问题! 请教各位!
小弟初学struts, 被struts的配置问题困扰很久拉, 查了些资料拼凑出下面的代码, 可是运行总是报错! 哪位高手救救我!
目录结构:
站点根目录下:
struts1.3.5中lib目录下的所有jar包都存入\WEB-INF\lib中
\WEB-INF\classes\mt\newProblem\newProblem\action\NewProblemAction.class
\WEB-INF\web.xml
\WEB-INF\struts-config.xml
\testStruts.jsp
文件:web.xml:
<?xml version= "1.0 " encoding= "ISO-8859-1 "?>
<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN "
"http://java.sun.com/dtd/web-app_2_3.dtd ">
<web-app>
<display-name> Struts Blank Application </display-name>
<!-- Standard Action Servlet Configuration -->
<servlet>
<servlet-name> action </servlet-name>
<servlet-class> org.apache.struts.action.ActionServlet </servlet- class>
<init-param>
<param-name> config </param-name>
<param-value> /WEB-INF/struts-config.xml </param-value>
</init-param>
<init-param>
<param-name> debug </param-name>
<param-value> 3 </param-value>
</init-param>
<init-param>
<param-name> detail </param-name>
<param-value> 3 </param-value>
</init-param>
<load-on-startup> 0 </load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name> action </servlet-name>
<url-pattern> *.do </url-pattern>
</servlet-mapping>
</web-app>
-----------------------web.xml结束--------
文件:struts-config.xml:
<?xml version= "1.0 " encoding= "ISO-8859-1 " ?>
<!DOCTYPE struts-config PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 1.3//EN "
"http://struts.apache.org/dtds/struts-config_1_3.dtd ">
<struts-config>
<action-mapping>
<action path= "/test "
type= "mt.newProblem.newPorblem.action.NewProblemAction ">
<forward name= "success " path= "testStruts.jsp "/>
</action>
</action-mapping>
</struts-config>
-----------------------struts-config.xml结束--------
action类:
package mt.newProblem.newPorblem.action;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.*;
public class NewProblemAction extends Action {
public ActionForward execute(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response) throws Exception {
return mapping.findForward( "success ");
}
}
--------------action类结束-----------
weblogic8
访问http://localhost:7001/myWeb/test.do后报错:
Error 500--Internal Server Error
org.apache.struts.chain.commands.InvalidPathException: No action config found for the specified url.
at org.apache.struts.chain.commands.AbstractSelectAction.execute(AbstractSelectAction.java:68)
at org.apache.struts.chain.commands.ActionCommandBase.execute(ActionCommandBase.java:48)
at org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:190)
at org.apache.commons.chain.generic.LookupCommand.execute(LookupCommand.java:304)
at org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:190)
at org.apache.struts.chain.ComposableRequestProcessor.process(ComposableRequestProcessor.java:280)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1858)
at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:446)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at weblogic.servlet.internal.ServletStubImpl$ServletInvocationAction.run(ServletStubImpl.java:1072)
at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:465)
at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:348)
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:6981)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:121)
at weblogic.servlet.internal.WebAppServletContext.invokeServlet(WebAppServletContext.java:3892)
at weblogic.servlet.internal.ServletRequestImpl.execute(ServletRequestImpl.java:2766)
at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:224)
at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:183)
[解决办法]
配置文件应该没问题,可能是WEB路径不对。直接输http://localhost:7001/myWeb/testStruts.jsp能访问吗。
[解决办法]
你使用IDE了吗?如果没有,那你是否配置好了jdk和Tomcat的环境变量?你的myWeb是否是放在tomcat/webapps/下。
[解决办法]
不可能是路径问题,路径问题weblogic只会显示找不到网页
[解决办法]
<forward name= "success " path= "/testStruts.jsp "/>
[解决办法]
struts-config.xml里面加上 <forward name= "success " path= "/testStruts.jsp " />
[解决办法]
你的struts-config.xml放在\WEB-INF\下了么?
[解决办法]
首先怎么说呢?
你没有formbean 的配置
例如:
<form-beans type= "org.apache.struts.action.ActionFormBean ">
<form-bean name= "loginForm " type= "login.source.form.LoginForm "/>
</form-beans>
<action-mappings>
<action
path= "/login "
type= "login.source.action.LoginAction "
name= "loginForm "
scope= "request "
input= "/login.jsp ">
<forward name= "Success " path= "/users.jsp " redirect= "true "/>
<forward name= "Failure " path= "/login.jsp " redirect= "true "/>
</action>
</action-mappings>
这才算是一个action 与actionform的搭配
一个submit应该有一个action,每个action应该有它的form阿,一个jsp页面也应该对应一个form吧。你的action太随意了
[解决办法]
很明显是没有formbean,楼主要注意每一个action都必须要有对应的formbean,就是set,get之类的东西.
[解决办法]
这是我正应用的 配置文件 好多ACTION都没有FORM 为什么没错呢?
LZ的 <action-mapping> 应该写为 <action-mappings>
大哥您们能不能不要勿人呀。。。。。。。
<?xml version= "1.0 " encoding= "UTF-8 "?>
<!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>
<data-sources>
<data-source key= "noticemanagerDB " type= "org.apache.commons.dbcp.BasicDataSource ">
<set-property property= "driverClassName " value= "org.gjt.mm.mysql.Driver " />
<set-property property= "url " value= "jdbc:mysql://localhost:3306/noticemanager " />
<set-property property= "username " value= "root " />
<set-property property= "password " value= "root " />
</data-source>
</data-sources>
<form-beans>
<form-bean name= "adminLoginForm " type= "nm.admin.form.AdminLoginForm " />
<form-bean name= "userInfoForm " type= "nm.admin.form.UserInfoForm " />
<form-bean name= "userLoginForm " type= "nm.user.form.UserLoginForm " />
<form-bean name= "newNoticeForm " type= "nm.user.form.NewNoticeForm " />
<form-bean name= "noticeModifyForm " type= "nm.user.form.NoticeModifyForm " />
</form-beans>
<global-exceptions />
<global-forwards>
<forward name= "ToUserList " path= "/admin/userlist.jsp " />
<forward name= "ToNewUser " path= "/admin/newuser.jsp " />
<forward name= "ToUserEdit " path= "/admin/useredit.jsp " />
<forward name= "ToNoticeList " path= "/user/noticelist.jsp " />
<forward name= "ToErrorPage " path= "/common/messagepage.jsp " />
<forward name= "ToNoticeModify " path= "/user/noticemodify.jsp " />
<forward name= "ToNewNotice " path= "/user/newnotice.jsp " />
<forward name= "ToUserLogin " path= "/user/userlogin.jsp " />
<forward name= "ToAdminLogin " path= "/admin/adminlogin.jsp " />
</global-forwards>
<action-mappings>
<action path= "/adminloginjsp " forward= "/admin/adminlogin.jsp " />
<action path= "/adminlogin "
type= "nm.admin.action.AdminLoginAction "
name= "adminLoginForm "
scope= "request "
input= "/common/messagepage.jsp " />
<action path= "/checkpower " type= "nm.CheckPowerAction " />
<action path= "/newuser "
type= "nm.admin.action.NewUserAction "
name= "userInfoForm "
scope= "request "
input= "/common/messagepage.jsp " />
<action path= "/usersearch "
type= "nm.admin.action.UserSearchAction "
name= "userInfoForm "
scope= "request "
input= "/common/messagepage.jsp " />
<action path= "/useredit "
type= "nm.admin.action.UserEditAction "
name= "userInfoForm "
scope= "request "
input= "/common/messagepage.jsp " />
<action path= "/userloginjsp " forward= "/user/userlogin.jsp " />
<action path= "/userlogin "
type= "nm.user.action.UserLoginAction "
name= "userLoginForm "
scope= "request "
input= "/common/messagepage.jsp " />
<action path= "/noticelistjsp " forward= "/user/noticelist.jsp " />
<action path= "/noticemodifyjsp "
forward= "/user/noticemodify.jsp " />
<action path= "/newnotice "
type= "nm.user.action.NewNoticeAction "
name= "newNoticeForm "
scope= "request " input= "/user/newnotice.jsp " />
<action path= "/noticemodify "
type= "nm.user.action.NoticeModifyAction " name= "noticeModifyForm "
scope= "request " input= "/user/noticemodify.jsp " />
<action path= "/adminlogoff " type= "nm.admin.action.AdminLogoffAction " />
<action path= "/userlogoff " type= "nm.user.action.UserLogoffAction " />
</action-mappings>
<message-resources parameter= "nm.ApplicationResources_zh " />
</struts-config>
[解决办法]
struts-config.xml,web.xml,action等,楼主是手写的还是工具生成的。。。
如果才用,生成比较容易。
没用过weblogic.....