各位大侠,我是学习j2ee的新手,最新发现我的struts2有一点问题。
我在Action中的Excute()方法里面使用System.out.println("该Action被调用")方法,启动Action后控制台没有打印出任何东西,是不是我的配置有问题呢?启动struts2的必需的包已经放到里面了。
希望各位高手指点一下

解决方案 »

  1.   

    你的代码怎么写的,是不是报异常了,或者你的action根本就没有调用
      

  2.   

    没报任何异常,而且action也返回字符串了,页面也转到了转发页面,但就是打印不出东西
      

  3.   

    一下是代码 
    index.jsp
    <%@ page language="java" import="java.util.*" pageEncoding="GBK"%>
    <%@taglib prefix="s" uri="/struts-tags"%>
    <%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
    %><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
      <head>
        <base href="<%=basePath%>">
        
        <title>测试两种程序结合</title>
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">    
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="This is my page">
    <!--
    <link rel="stylesheet" type="text/css" href="styles.css">
    -->
      </head>
      
      <body>
           <s:form action="findUrl">
            <table width="100%" border="1">
                <tr>
                       <td align="right" width="50%">请输入你需要的商品:</td>
                       <td align="left" width="50%"><s:textfield name="name"  theme="simple"/>
                       <s:submit value="查询" theme="simple" /></td>
                </tr>
               
            </table>
             <br>
             </s:form>
      </body>
    </html>findUrlAction.java
    import com.opensymphony.xwork2.ActionSupport;
    public class findUrlAction extends ActionSupport{

     
    public String excute() throws Exception{
    System.out.println("已经执行action");

    return SUCCESS;
    }}
    web.xml
    <?xml version="1.0" encoding="UTF-8"?>
    <web-app version="2.5" 
    xmlns="http://java.sun.com/xml/ns/javaee" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
    http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">

       <filter>
            <filter-name>struts2</filter-name>
            <filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
        </filter>    <filter-mapping>
            <filter-name>struts2</filter-name>
            <url-pattern>/*</url-pattern>
        </filter-mapping>
        
       
        
        <welcome-file-list>
         <welcome-file>index.jsp</welcome-file>
        </welcome-file-list>
        
    </web-app>struts.xml
    <?xml version="1.0" encoding="GBK"?>
    <!DOCTYPE struts PUBLIC
            "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
            "http://struts.apache.org/dtds/struts-2.0.dtd">
    <struts>
        
    <package name="test" extends="struts-default">
        <action name="findUrl" class="findUrlAction">
            <result name="success" >suc.jsp</result>

        </action>
      

    </package>     
     
       </struts>
      

  4.   

    是不是你打印的东西被淹没在一大堆的log里了?
    不可能打不出来的。
      

  5.   

    没打印
    就是没调用到那个action
      

  6.   

    听你说启动action总觉得好别扭~~用debug模式启动,就是启动按钮旁边那个虫子,然后在你的excute()方法里面设个断点,就是在方法里面system.out..那行的行标上双击下有个绿点点~然后看会不会跑到那行.
      

  7.   

    System.out.println()你是后来加上去的吧。重启下服务器
      

  8.   

    如果Action以被调用的话,ActionForm没有获取到值时,后面的Sysout.out.println也不会在控制台打印值,网页会报错
      

  9.   

    我重新发布过了,然后重启过,但程序没报错也没打印出东西,我设置了struts.xml接受到Action的字符返回就要跳转,它也跳转了,我查了一下百度,说struts-confing配置也有可能影响。但我还是找不到原因所在
      

  10.   

    2009-12-17 21:46:58 org.apache.catalina.core.AprLifecycleListener init
    信息: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: C:\Genuitec\Common\binary\com.sun.java.jre.win32.x86_1.5.0.011\bin;C:\Tomcat 6.0\bin
    2009-12-17 21:46:59 org.apache.coyote.http11.Http11Protocol init
    信息: Initializing Coyote HTTP/1.1 on http-8080
    2009-12-17 21:46:59 org.apache.catalina.startup.Catalina load
    信息: Initialization processed in 1270 ms
    2009-12-17 21:46:59 org.apache.catalina.core.StandardService start
    信息: Starting service Catalina
    2009-12-17 21:46:59 org.apache.catalina.core.StandardEngine start
    信息: Starting Servlet Engine: Apache Tomcat/6.0.20
    log4j:WARN No appenders could be found for logger (org.springframework.web.context.ContextLoader).
    log4j:WARN Please initialize the log4j system properly.
    2009-12-17 21:47:01 org.apache.catalina.core.ApplicationContext log
    信息: Loading Spring root WebApplicationContext
    2009-12-17 21:47:13 com.opensymphony.xwork2.config.providers.XmlConfigurationProvider register
    信息: Parsing configuration file [struts-default.xml]
    2009-12-17 21:47:14 com.opensymphony.xwork2.config.providers.XmlConfigurationProvider register
    信息: Parsing configuration file [struts-plugin.xml]
    2009-12-17 21:47:14 com.opensymphony.xwork2.config.providers.XmlConfigurationProvider register
    信息: Parsing configuration file [struts.xml]
    2009-12-17 21:47:14 org.apache.struts2.config.Settings getLocale
    警告: Settings: Could not parse struts.locale setting, substituting default VM locale
    2009-12-17 21:47:15 com.opensymphony.xwork2.util.ObjectTypeDeterminerFactory <clinit>
    信息: Setting DefaultObjectTypeDeterminer as default ...
    2009-12-17 21:47:15 org.apache.coyote.http11.Http11Protocol start
    信息: Starting Coyote HTTP/1.1 on http-8080
    2009-12-17 21:47:15 org.apache.jk.common.ChannelSocket init
    信息: JK: ajp13 listening on /0.0.0.0:8009
    2009-12-17 21:47:16 org.apache.jk.server.JkMain start
    信息: Jk running ID=0 time=0/203  config=null
    2009-12-17 21:47:16 org.apache.catalina.startup.Catalina start
    信息: Server startup in 17087 ms
    2009-12-17 21:47:45 com.opensymphony.xwork2.validator.ActionValidatorManagerFactory <clinit>
    信息: Detected AnnotationActionValidatorManager, initializing it...提交表单之后的控制台信息
      

  11.   

    呵呵, 你太粗心了~~  在你的 "execute" 方法上面打上  
    @Override  (重写了 ActionSupport 类中的 execute方法) 注解试一下看看~~ :) 方法名写错了