你在struts.xml中配置了名叫login的action吧?<a href="login.action">登录系统</a>这段代码就是表示访问的login这个action啊。
你这可以在LoginAction里面加一个方法:
public String execute() {
  
    return "login".
}
这样就可以了。

解决方案 »

  1.   

    不经后台不好直接转到jsp的,因为你的jsp放在了/WEB-INF/下,要是你的jsp文件放在了/WEB-INF/的上层目录,可直接通过<a href="xx.jsp" 进行跳转
      

  2.   

    web.xml中struts会根据<url-pattern>参数值过滤请求,
    <filter-mapping>
        <filter-name>struts2</filter-name>
        <url-pattern>/*</url-pattern>
      </filter-mapping>
    楼主的链接应该被struts过滤了,然后struts找到对应的action处理了
      

  3.   

    你的struts里写的LoginAction.java导向问题。
      

  4.   


    谢谢你的回复,但我写的是login.action跳转,不是页面跳转,经过action了
      

  5.   


    关键是struts.xml中没有配置名叫login的action
    以下是我struts.xml的所有配置:
    <?xml version="1.0" encoding="UTF-8" ?>
    <!-- 指定Struts2配置文件的DTD信息 -->
    <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">
    <!-- Struts2配置文件的根元素 -->
    <struts>
    <!-- 配置了系列常量 -->
    <constant name="struts.custom.i18n.resources" value="resource" />
    <constant name="struts.i18n.encoding" value="utf-8" />
    <constant name="struts.devMode" value="true" />
    <package name="cb" extends="struts-default" >
    <!-- 定义全局Result映射 -->
    <global-results>
    <!-- 定义全局Result映射 -->
    <result name="business">/WEB-INF/content/error.jsp</result>
    <result name="root">/WEB-INF/content/error.jsp</result>
    <!-- 定义login逻辑视图对应的视图资源 -->
    <result name="login">/WEB-INF/content/login.jsp</result>
    </global-results>
    </package>
    </struts> 还有一个问题,就是说我LoginAction中即使没有继承ActionSupport,它也会执行execute()这个方法,但是我把这个方法名改个名字,它就不会执行了,太奇怪了,谢谢你的解答!
      

  6.   


    struts里都没有配置Login这个action,一共就三个全局Result映射
      

  7.   


    struts里都没有配置Login这个action,一共就三个全局Result映射能不能贴下你的action配置啊
      

  8.   


    struts里都没有配置Login这个action,一共就三个全局Result映射能不能贴下你的action配置啊7楼我贴出来了
      

  9.   


    关键是struts.xml中没有配置名叫login的action
    以下是我struts.xml的所有配置:
    <?xml version="1.0" encoding="UTF-8" ?>
    <!-- 指定Struts2配置文件的DTD信息 -->
    <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">
    <!-- Struts2配置文件的根元素 -->
    <struts>
    <!-- 配置了系列常量 -->
    <constant name="struts.custom.i18n.resources" value="resource" />
    <constant name="struts.i18n.encoding" value="utf-8" />
    <constant name="struts.devMode" value="true" />
    <package name="cb" extends="struts-default" >
    <!-- 定义全局Result映射 -->
    <global-results>
    <!-- 定义全局Result映射 -->
    <result name="business">/WEB-INF/content/error.jsp</result>
    <result name="root">/WEB-INF/content/error.jsp</result>
    <!-- 定义login逻辑视图对应的视图资源 -->
    <result name="login">/WEB-INF/content/login.jsp</result>
    </global-results>
    </package>
    </struts> 还有一个问题,就是说我LoginAction中即使没有继承ActionSupport,它也会执行execute()这个方法,但是我把这个方法名改个名字,它就不会执行了,太奇怪了,谢谢你的解答!Struts本来就是这样的,你自己写的action不用继承ActionSupport也可以执行,只是这样你就不能用ActionSupport的一些功能了,比如validate()、addFieldError()等等。
      

  10.   


    关键是struts.xml中没有配置名叫login的action
    以下是我struts.xml的所有配置:
    <?xml version="1.0" encoding="UTF-8" ?>
    <!-- 指定Struts2配置文件的DTD信息 -->
    <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">
    <!-- Struts2配置文件的根元素 -->
    <struts>
    <!-- 配置了系列常量 -->
    <constant name="struts.custom.i18n.resources" value="resource" />
    <constant name="struts.i18n.encoding" value="utf-8" />
    <constant name="struts.devMode" value="true" />
    <package name="cb" extends="struts-default" >
    <!-- 定义全局Result映射 -->
    <global-results>
    <!-- 定义全局Result映射 -->
    <result name="business">/WEB-INF/content/error.jsp</result>
    <result name="root">/WEB-INF/content/error.jsp</result>
    <!-- 定义login逻辑视图对应的视图资源 -->
    <result name="login">/WEB-INF/content/login.jsp</result>
    </global-results>
    </package>
    </struts> 还有一个问题,就是说我LoginAction中即使没有继承ActionSupport,它也会执行execute()这个方法,但是我把这个方法名改个名字,它就不会执行了,太奇怪了,谢谢你的解答!Struts本来就是这样的,你自己写的action不用继承ActionSupport也可以执行,只是这样你就不能用ActionSupport的一些功能了,比如validate()、addFieldError()等等。谢谢你的回答,这个问题我明白了,但是你能帮我看看,为什么LoginAction没在struts里面配置,但是它会自动加载吗?
      

  11.   

    把你LoginAction的代码完整的贴出来看看
      

  12.   

    你是不是引入了Struts-rest的包? rest的包会自动扫描Class 若有JAVA文件名为Action结尾的,都会默认是Action
      

  13.   


    package com.cb.hrsystem.action;import com.opensymphony.xwork2.Action;
    import com.opensymphony.xwork2.ActionSupport;public class LoginAction implements Action{
    public String execute() throws Exception{
    System.out.println("测试");
    return "";
    }
    }
      

  14.   


    extends="struts-default"没有应用Struts-rest的包,7楼有struts.xml配置
      

  15.   

    我自己试了,没有你的这个问题,不知道什么情况了。
    其实你也别这么纠结一定要把这种问题刨根问底,按照struts2正常的配置来写就好了。
      

  16.   


    非常感谢你的回答!我自己找出什么问题了,我这个struts的版本估计有问题,我是2.2.1的,struts配置里面必须要namespace="/".否则,使用action的名字是login,logout都存在这个问题,会自己寻找loginaction,login.jsp!
      

  17.   


    非常感谢你的回答!我自己找出什么问题了,我这个struts的版本估计有问题,我是2.2.1的,struts配置里面必须要namespace="/".否则,使用action的名字是login,logout都存在这个问题,会自己寻找loginaction,login.jsp!
    你是说struts2会对login、logout做特别处理吗?
      

  18.   

    建议不要把文件放在web-inf文件夹下。
      

  19.   


    非常感谢你的回答!我自己找出什么问题了,我这个struts的版本估计有问题,我是2.2.1的,struts配置里面必须要namespace="/".否则,使用action的名字是login,logout都存在这个问题,会自己寻找loginaction,login.jsp!
    你是说struts2会对login、logout做特别处理吗?目前看来是这个问题,我只要使用这两个action的名字,都存在这个问题!就这样,结贴了额,感谢你们的回答