web.xml中配置:
<?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" version="2.5">
  <display-name></display-name>
  
  <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="UTF-8"?><!DOCTYPE struts PUBLIC
    "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
    "http://struts.apache.org/dtds/struts-2.3.dtd">
 
<struts>
<package name="example" namespace="/" extends="struts-default">
<action name="user" class="com.amaker.action.UserAction">
<result name="loginOk">/loginOk.jsp</result>
<result name="registOK">/registOK.jsp</result>
</action>
</package>
</struts>

解决方案 »

  1.   

    action 被调用的方法里呢?
      

  2.   

    com.amaker.action.UserAction类中代码package com.amaker.action;import com.opensymphony.xwork2.ActionSupport;public class UserAction extends ActionSupport{ public String login() throws Exception {
    System.out.println("login......");
    return "loginOK";
    }

    public String register() throws Exception {
    System.out.println("regist......");
    return "registOK";
    }
    }Test.jsp代码:
    <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
    <%
    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>My JSP 'Test.jsp' starting page</title>
      </head>
      
      <body>
        <a href="<%=path %>/user!login.action">Login</a>| <a href="<%=path %>/user!register.action">Register</a>
      </body>
    </html>
      

  3.   

    你看看是不是struts2的fiter写错了
    <filter>
    <filter-name>struts2</filter-name>
    <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
    </filter>
    <filter-mapping>
    <filter-name>struts2</filter-name>
    <url-pattern>/*</url-pattern>
    </filter-mapping>
      

  4.   

    <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
      

  5.   

    看楼主在action中的输出都没在控制台打印出来,程序没有跑进去
      

  6.   

    <a href="<%=path %>/user!login.action">Login</a>| <a href="<%=path %>/user!register.action">Register</a>中的user应该大写吧
      

  7.   

    struts的配置文件里如果不指定method,会调用默认的execute方法吧?
      

  8.   

    是不是没有在struts.xml里加入    <constant name="struts.enable.DynamicMethodInvocation" value="true" /> 这句话 ,貌似在struts2.3版本还是什么版本以后 动态方法调用的话 默认设成FALSE 了 ,必须手动设置成TRUE才有效,可以试一下。
      

  9.   

    一般项目中不怎么用DMI,如果是学习的话, 可以了解下,使用前记得打开DMI, struts2 默认是关闭的
      

  10.   

    感谢#9和#10的大哥,说的很有道理,也许就是在struts2.3以后DMI默认关闭,看的是以前的视频,没有发现问题所在,发帖后也没太留意正确答案,时至今日,再次遇到该问题,已经按照#9和#10楼大哥的方法解决了,非常感谢你们!
      

  11.   

    感谢#9和#10的大哥,说的很有道理,也许就是在struts2.3以后DMI默认关闭,看的是以前的视频,没有发现问题所在,发帖后也没太留意正确答案,时至今日,再次遇到该问题,已经按照#9和#10楼大哥的方法解决了,非常感谢你们!
      

  12.   

    感谢#9和#10的大哥,说的很有道理,也许就是在struts2.3以后DMI默认关闭,看的是以前的视频,没有发现问题所在,发帖后也没太留意正确答案,时至今日,再次遇到该问题,已经按照#9和#10楼大哥的方法解决了,非常感谢你们!