我的Action头执行得了System.out.println("\nscrip***************11******action=");也能打印,但是到了execute中的System.out.println("\nscrip*********************action=");执行不了,是什么原因?源码如下:
java.action
public class SongAction extends Action {
private SongDAO songDAO = null;
MyPagination pagination = null;
StringUtils su=new StringUtils();
public SongAction() {
this.songDAO = new SongDAO();
System.out.println("\nscrip***************11******action=");
}
public ActionForward execute(ActionMapping   mapping,ActionForm   form,HttpServletRequest   request,HttpServletResponse   response)throws   IOException,ServletException
{
System.out.println("\nscrip*********************action=");

 System.out.println("\nscrip*********************action=");
String action = request.getParameter("action");
 System.out.println("\nscrip*********************action="+action);
if ("main".equals(action)) {
return main(mapping, form, request, response); // 前台首页
} else if ("songQuery".equals(action)) {
return songQuery(mapping, form, request, response);  // 查询歌曲信息
} else if ("tryListen".equals(action)) {
return tryListen(mapping, form, request, response); // 查询试听歌曲信息
} else if ("continuePlay".equals(action)) {
return continuePlay(mapping, form, request, response); // 进行歌曲连播
} else if ("songSort".equals(action)) {
return songSort(mapping, form, request, response);  // 歌曲排行(试听和下载)
} else if ("navigation".equals(action)) {
return navigation(mapping, form, request, response);  // 查询导航栏信息
} else if ("search".equals(action)) {
return search(mapping, form, request, response);  // 按条件查询歌曲
} else if ("download".equals(action)) {
return download(mapping, form, request, response);  // 文件下载
} else if ("songType".equals(action)) {
return songType(mapping, form, request, response);  // 查询歌曲类别
} else if ("adm_search".equals(action)) {
return adm_search(mapping, form, request, response);  // 后台查询歌曲信息
} else if ("add".equals(action)){
return adm_add(mapping,form,request,response); //添加歌曲信息
} else if ("checkMusic".equals(action)){
return checkMusic(mapping,form,request,response); //检测歌曲是否已经添加
} else if ("del".equals(action)) {
return del(mapping, form, request, response);  // 删除歌曲信息
} else {
request.setAttribute("error", "操作失败!");
return mapping.findForward("error");
}
}
Confing.xml:<struts-config>
  <data-sources />
  <form-beans>
   <form-bean name="songForm" type="com.model.SongForm"/>
   <form-bean name="managerForm" type="com.model.ManagerForm"/>
  </form-beans>
  <global-exceptions />
    <global-forwards /> 
  
  <action-mappings>
   <action name="songForm" path="/song" scope="request" input="/index.jsp" type="com.action.SongAction" validate="true">
   <forward name="main" path="/main.jsp"/>
   <forward name="songQuery" path="/songList.jsp"/>
   <forward name="search" path="/searchResult.jsp"/>
   <forward name="download" path="/download.jsp"/>
   <forward name="tryListen" path="/tryListen.jsp"/>
   <forward name="continuePlay" path="/continuePlay.jsp"/>
   <forward name="adm_search" path="/adm_main.jsp"/>
   <forward name="addok" path="/addok.jsp"/>
   <forward name="checkMusic" path="/checkMusic.jsp"></forward>
   <forward name="delok" path="/delok.jsp"/>
   <forward name="error" path="/error.jsp"/>
   </action>
      <action name="managerForm" path="/manager" scope="request" type="com.action.ManagerAction" validate="true">
   <forward name="managerLoginok" path="/login_ok.jsp"/>
   <forward name="error" path="/error.jsp"/>
   </action>
  </action-mappings>
  <controller processorClass="com.action.SelfRequestProcessor" />
  <message-resources parameter="com.yourcompany.struts.ApplicationResources" />
</struts-config>

解决方案 »

  1.   

    不知道说么事,你的excute方法是覆盖了Actionsupport的方法吗?
      

  2.   

    请说具体点好吗?我的
    public SongAction() {
    this.songDAO = new SongDAO();
    System.out.println("\nscrip***************11******action=");
    }
    能够执行的,但是接下来的execute没有执行,怎么回事啊???
      

  3.   

    <?xml version="1.0" encoding="UTF-8"?>
    <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
      <display-name>lipincheng</display-name>
      <welcome-file-list>
        <welcome-file>index.html</welcome-file>
        <welcome-file>index.htm</welcome-file>
        <welcome-file>index.jsp</welcome-file>
      </welcome-file-list>
      <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>
      <welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
      </welcome-file-list>
    </web-app>
    这是web.xml
      

  4.   

    控制台的部分信息,信息显示Action一部分是被执行了,但是excute里面确实执行不了!
    2011-10-25 12:53:51 org.apache.catalina.core.ApplicationContext log
    信息: action: Process servletName=action, urlPattern=*.do
    2011-10-25 12:53:51 org.apache.catalina.core.ApplicationContext log
    信息: action: Mapping for servlet 'action' = '*.do'
    2011-10-25 12:53:52 com.opensymphony.xwork2.config.providers.XmlConfigurationProvider register
    信息: Parsing configuration file [struts-default.xml]
    2011-10-25 12:53:52 com.opensymphony.xwork2.config.providers.XmlConfigurationProvider register
    信息: Parsing configuration file [struts-plugin.xml]
    2011-10-25 12:53:52 com.opensymphony.xwork2.config.providers.XmlConfigurationProvider register
    信息: Parsing configuration file [struts.xml]
    2011-10-25 12:53:52 org.apache.struts2.config.Settings getLocale
    警告: Settings: Could not parse struts.locale setting, substituting default VM locale
    2011-10-25 12:53:52 com.opensymphony.xwork2.util.ObjectTypeDeterminerFactory <clinit>
    信息: Setting DefaultObjectTypeDeterminer as default ...
    2011-10-25 12:53:53 org.apache.coyote.http11.Http11Protocol start
    信息: Starting Coyote HTTP/1.1 on http-8080
    2011-10-25 12:53:53 org.apache.jk.common.ChannelSocket init
    信息: JK: ajp13 listening on /0.0.0.0:8009
    2011-10-25 12:53:53 org.apache.jk.server.JkMain start
    信息: Jk running ID=0 time=0/79  config=null
    2011-10-25 12:53:53 org.apache.catalina.startup.Catalina start
    信息: Server startup in 7633 ms
    asdfasfsafsdasassssssssssssssssssss
    2011-10-25 12:53:57 org.apache.catalina.core.ApplicationContext log
    信息: action: Processing a GET for /song
    2011-10-25 12:53:57 org.apache.catalina.core.ApplicationContext log
    信息: action: Setting locale 'zh_CN'
    2011-10-25 12:53:57 org.apache.catalina.core.ApplicationContext log
    信息: action:  Looking for ActionForm bean under attribute 'songForm'
    2011-10-25 12:53:57 org.apache.catalina.core.ApplicationContext log
    信息: action:  Creating new ActionForm instance of class 'com.model.SongForm'
    2011-10-25 12:53:58 org.apache.catalina.core.ApplicationContext log
    信息: action:  Storing instance under attribute 'songForm' in scope 'request'
    2011-10-25 12:53:58 org.apache.catalina.core.ApplicationContext log
    信息: action:  Populating bean properties from this request
    2011-10-25 12:53:58 org.apache.catalina.core.ApplicationContext log
    信息: action:  Validating input form properties
    2011-10-25 12:53:58 org.apache.catalina.core.ApplicationContext log
    信息: action:   No errors detected, accepting input
    2011-10-25 12:53:58 org.apache.catalina.core.ApplicationContext log
    信息: action:  Looking for Action instance for class com.action.SongAction
    2011-10-25 12:53:58 org.apache.catalina.core.ApplicationContext log
    信息: action:   Double checking for Action instance already there
    2011-10-25 12:53:58 org.apache.catalina.core.ApplicationContext log
    信息: action:   Creating new Action instancescrip***************11******action=
      

  5.   

    public SongAction() {
    this.songDAO = new SongDAO();
    System.out.println("\nscrip***************11******action=");
    }
    应该是程序初始化的时候执行的。
    你那个请求应该都没有到后台
      

  6.   

    怎么样才能让我的请求到后台呢?这是我的配置
    <struts-config>
      <data-sources />
      <form-beans>
       <form-bean name="songForm" type="com.model.SongForm"/>
       <form-bean name="managerForm" type="com.model.ManagerForm"/>
      </form-beans>
      <global-exceptions />
      <global-forwards />  
      <action-mappings>
       <action name="songForm" path="/song" scope="request" input="/index.jsp" type="com.action.SongAction" validate="true">
       <forward name="main" path="/main.jsp"/>
       <forward name="songQuery" path="/songList.jsp"/>
       <forward name="search" path="/searchResult.jsp"/>
       <forward name="download" path="/download.jsp"/>
       <forward name="tryListen" path="/tryListen.jsp"/>
       <forward name="continuePlay" path="/continuePlay.jsp"/>
       <forward name="adm_search" path="/adm_main.jsp"/>
       <forward name="addok" path="/addok.jsp"/>
       <forward name="checkMusic" path="/checkMusic.jsp"></forward>
       <forward name="delok" path="/delok.jsp"/>
       <forward name="error" path="/error.jsp"/>
       </action>
          <action name="managerForm" path="/manager" scope="request" type="com.action.ManagerAction" validate="true">
       <forward name="managerLoginok" path="/login_ok.jsp"/>
       <forward name="error" path="/error.jsp"/>
       </action>
      </action-mappings>
      <controller processorClass="com.action.SelfRequestProcessor" />
      <message-resources parameter="com.yourcompany.struts.ApplicationResources" />
    </struts-config>