superjcn 2012-07-17 19:46
浏览 260
已采纳

刚学习struts,遇到一个问题,特此向各位请教!!!

首先是一个index.jsp,里面用到了<frameset></frameset>,代码如下:

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ include file="../common/common.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<base href="${pageScope.basePath}">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="Cache-Control" content="no-cache">
<meta http-equiv="Expires" content="0">
<title>主页-管理者页面</title>
<link href="css/style.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="js/adminindex.js"></script>
</head>
<frameset>
<frame src="admin/redirpage.action"></frame>
</frameset>
</html>

  <frame>的src是一个action,这是我的action配置(struts.xml),请看<package name="admin" namespace="/admin">的包:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
 "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
 "http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
    
    <constant name="struts.enable.DynamicMethodInvocation" value="true"/>
    <constant name="struts.devMode" value="true"/>
    <!--Common package-->
    <package name="common" namespace="/" extends="struts-default">
        <!--iframe页面包含跳转-->
        <!--登录跳转-->
        <action name="login">
            <result>
                /WEB-INF/views/login.jsp
            </result>
        </action>
        <!--登录验证-->
        <action name="check*" class="net.yuanedu.action.AdminAction" method="{1}">
            <!--与Ajax有关的用户名、密码、验证码校验-->
            <result name="success" type="stream">
                <!-- 指定下载文件的文件类型 -->
                <param name="contentType">
                    text/html
                </param>
                <!-- 指定由getResult()方法返回输出结果的InputStream -->
                <param name="inputName">
                    inputStream
                </param>
            </result>
            <!--角色判断-->
            <result name="admin" type="redirectAction">
                /Admin_login.action
            </result>
            <result name="commissioner" type="redirectAction">
                /Commissioner_login.action
            </result>
            <result name="finance" type="redirectAction">
                /Finance_login.action
            </result>
            <result name="reception" type="redirectAction">
                /Reception_login.action
            </result>
        </action>
        <!--主页跳转-->
        <action name="*_*" class="net.yuanedu.action.{1}Action" method="{2}">
            <result name="success">
                /WEB-INF/views/{1}/index.jsp
            </result>
        </action>
    </package>
    <!--Admin package-->
    <package  name="admin"  namespace="/admin"  extends="struts-default">
        <action  name="redirpage"  class="net.yuanedu.action.RedirectAction">
            <result  name="jump">a.jsp</result>
        </action>
    </package>
    
    <!--Commissioner package-->
    <package name="commissioner" namespace="/commissioner" extends="struts-default">
        
    </package>
    
    <!--Finance package-->
    <package name="finance" namespace="/finance" extends="struts-default">
        
    </package>
    
    <!--Reception package-->
    <package name="reception" namespace="/reception" extends="struts-default">
        
    </package>
</struts>

 现在的问题是,我跑index.jsp,报不能实例化Action的错误(Unable to instantiate Action)。我检查了好久,也怀疑过是namespace的问题,但是我都试过了,还是一样的错误提示。通配符的问题我也调试过,还是没有解决。现在怀疑是jar包的问题。请各位指教,希望能给出详细的解答,非常谢谢!!!。下面是错误提示:

Struts Problem Report

Struts has detected an unhandled exception:
Messages:   

    net.yuanedu.action.redirpageAction
    Unable to instantiate Action, net.yuanedu.action.redirpageAction, defined for 'redirpage' in namespace '/'net.yuanedu.action.redirpageAction

File:   org/apache/catalina/loader/WebappClassLoader.java
Line number:    1,645
Stacktraces
Unable to instantiate Action, net.yuanedu.action.redirpageAction, defined for 'redirpage' in namespace '/'net.yuanedu.action.redirpageAction

    com.opensymphony.xwork2.DefaultActionInvocation.createAction(DefaultActionInvocation.java:318)
    com.opensymphony.xwork2.DefaultActionInvocation.init(DefaultActionInvocation.java:399)
    com.opensymphony.xwork2.DefaultActionProxy.prepare(DefaultActionProxy.java:198)
    org.apache.struts2.impl.StrutsActionProxy.prepare(StrutsActionProxy.java:61)
    org.apache.struts2.impl.StrutsActionProxyFactory.createActionProxy(StrutsActionProxyFactory.java:39)
    com.opensymphony.xwork2.DefaultActionProxyFactory.createActionProxy(DefaultActionProxyFactory.java:58)
    org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:475)
    org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:395)
    org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
    org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
    org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
    org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
    org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
    org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
    org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
    org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:857)
    org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
    org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
    java.lang.Thread.run(Unknown Source)
    

java.lang.ClassNotFoundException: net.yuanedu.action.redirpageAction

    org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1645)
    org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1491)
    com.opensymphony.xwork2.util.ClassLoaderUtil.loadClass(ClassLoaderUtil.java:157)
    com.opensymphony.xwork2.ObjectFactory.getClassInstance(ObjectFactory.java:107)
    com.opensymphony.xwork2.ObjectFactory.buildBean(ObjectFactory.java:160)
    com.opensymphony.xwork2.ObjectFactory.buildBean(ObjectFactory.java:150)
    com.opensymphony.xwork2.ObjectFactory.buildAction(ObjectFactory.java:120)
    com.opensymphony.xwork2.DefaultActionInvocation.createAction(DefaultActionInvocation.java:299)
    com.opensymphony.xwork2.DefaultActionInvocation.init(DefaultActionInvocation.java:399)
    com.opensymphony.xwork2.DefaultActionProxy.prepare(DefaultActionProxy.java:198)
    org.apache.struts2.impl.StrutsActionProxy.prepare(StrutsActionProxy.java:61)
    org.apache.struts2.impl.StrutsActionProxyFactory.createActionProxy(StrutsActionProxyFactory.java:39)
    com.opensymphony.xwork2.DefaultActionProxyFactory.createActionProxy(DefaultActionProxyFactory.java:58)
    org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:475)
    org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:395)
    org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
    org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
    org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
    org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
    org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
    org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
    org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
    org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:857)
    org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
    org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
    java.lang.Thread.run(Unknown Source)
    

You are seeing this page because development mode is enabled. Development mode, or devMode, enables extra debugging behaviors and reports to assist developers. To disable this mode, set:

  struts.devMode=false

in your WEB-INF/classes/struts.properties file. 

 注:这是小的CRM练习,没有用Spring,只用了Struts2和Hibernate

  • 写回答

3条回答 默认 最新

  • iteye_7115 2012-07-18 10:39
    关注

    我觉得可能是你有两个namespace,由于没找到对应的[color=darkred]命名空间[/color],所以当你前台调用:admin/redirpage.action 时,后台struts对应的是第一个namespace里的:




    /WEB-INF/views/{1}/index.jsp




    这个就会初始化net.yuanedu.action.redirpageAction 这个action,所以报错

    【注意:我这个地方所说的命名空间,java处理的时候不一样是admin哟,所以你要检查下所对应的完整路径是什么,如果路径是http://localhost:8080/webappname/xxx/yyy/zzz/index.action,则此action的namespace就得是/xxx/yyy/zzz 了】

    举个例子:
    假设URL=http://localhost:8080/webappname/xxx/yyy/zzz/index.action
    首先请求会发送到web服务器,web服务器会找到相应的webapp应用程序,然后根据struts.xml进行相应的处理,其中关于namespace的处理如下:
    首先会在struts.xml的namespace中找是否存在/xxx/yyy/zzz/,如果存在,则查看是否有action的name为index的,如果有则返回相对应的页面或操作,否则报错。
    如果不存在则查看namespace中是否存在/xxx/yyy/ ,如果存在,则查看是否有action的name为index的,如果有则返回相对应的页面或操作,否则报错。
    如果不存在则查看namespace中是否存/xxx/,如果存在,则查看是否有action的name为index的,如果有则返回相对应的页面或操作,否则报错。
    如果不存在则查看namespace中是否存/,查看是否有action的name为index的,如果有则返回相对应的页面或操作,否则报错!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 android报错 brut.common.BrutException: could not exec (exit code = 1)
  • ¥15 nginx反向代理获取ip,java获取真实ip
  • ¥15 eda:门禁系统设计
  • ¥50 如何使用js去调用vscode-js-debugger的方法去调试网页
  • ¥15 376.1电表主站通信协议下发指令全被否认问题
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥15 复杂网络,变滞后传递熵,FDA
  • ¥20 csv格式数据集预处理及模型选择
  • ¥15 部分网页页面无法显示!
  • ¥15 怎样解决power bi 中设置管理聚合,详细信息表和详细信息列显示灰色,而不能选择相应的内容呢?