刚接触struts2 按照网上的方法也能成功。用myeclipse8.5可以直接生成struts1框架,但在用struts2是遇到了问题!我是这么做的:
1.建立web工程
2.添加struts2支持(通过Myeclipse选项添加struts2),自动修改web.xml 并添加了struts.xml
3.添加LoginAction类(代码就不写了,应该不是这里的问题)
4.编辑struts.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>
<package name="struts2" extends="struts-default">
<action name="login" class="com.action.LoginAction">

<result name="success">/login_success.jsp</result>
<result name="failure">/login_failure.jsp</result>

</action>
</package>
</struts>    
5.调用。在from里面用了“action=login.action”
6.部署错误信息如下
如果 LoginAction返回的是success 
type Status reportmessage No result defined for action com.action.LoginAction and result successdescription The requested resource (No result defined for action com.action.LoginAction and result success) is not available.如果返回了failure
type Status reportmessage No result defined for action com.action.LoginAction and result failuredescription The requested resource (No result defined for action com.action.LoginAction and result failure) is not available.
请问struts2里面的xml到底该怎么写

解决方案 »

  1.   

    我解决了我加了一个jar包,咱们是少印了一个jar包,今天上午我找了一上午终于搞定了,你再加一个jar包到lib下,一共是这么多jar包:
    commons-fileupload-1.2.1.jar,
    commons-io-1.3.2.jar
    commons-logging-1.0.4.jar
    freeer-2.3.16.jar
    ognl-3.0.jar
    struts2-core-2.2.1.jar
    xwork-core-2.2.1.jar
    你可能是少引了第一个包。你试试吧,你写的没错,
      

  2.   


    我是用MyEclipse导入的啊,导入了一大堆包
      

  3.   

    <?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">
      <welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
      </welcome-file-list>
      <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>*.action</url-pattern>
      </filter-mapping></web-app>
    这个是导入struts时自动添加的 应该没问题
      

  4.   

    action中返回的值和struts.xml定义的不一样吧,楼主留意下.action中确定返回的事“success”?和XML中的一样吗?
      

  5.   

    肯定是一样的
    我刚才查了一下说是Myeclipse自动添加的包会有冲突,回去试试看能不能解决
      

  6.   

    估计你的LoginAction类写得有问题
      

  7.   

     <filter-class>
      org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
      </filter-class>
    这个貌似不对吧
      

  8.   

    我看了ActionSupport没有failure这个result,删掉试试
      

  9.   


    这个在2.1.8以后的版本就是提倡这样写的没问题。你把实际处理的action类代码发上来。可能jar包之间也会存在一些问题。把含有版本号的重复的jar包删掉。
      

  10.   

    <url-pattern>*.action</url-pattern>
    这个最好改一下,还有可能是你的LoginAction类中的方法有错。不知道你有没有继承ActionSupport接口啊!
      

  11.   


    谢谢大家,问题已经找到了。是Myeclipse自动添加的包有冲突,在struts.xml声明动作中要加上namespace=“/”。