struts 的xml
    <?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
    "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
    "http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>
     
     
    
     
       <package name="userLogin" extends="struts-default" namespace="/">
       
            <action name="login" class="com.struts2c.action.LoginAction">
            
                <result type="chain">test</result>
                <result name="error" type="redirect">/xz.jsp</result>
            </action> 
           
             <action name="test" class="com.struts2c.action.TestAction">
           
                <result type="dispatcher">/zx.jsp</result>
            </action> 
           
       </package>
       
</struts>
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">
  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>
  
  <filter>
     <filter-name>myStruts2</filter-name>
     <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
  
     <init-param>
        <param-name>struts.i18n.encoding</param-name>
        <param-value>gbk</param-value>
     </init-param>
    
     </filter>

  
  <filter-mapping>
     <filter-name>myStruts2</filter-name>
     <url-pattern>/*</url-pattern>
  </filter-mapping>
  
 
  
</web-app> <form action="login.action" method="post">//这个是请求
package com.struts2c.action;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;public class LoginAction extends ActionSupport implements ModelDriven<User>{
 User u=new User();

public String execute()
{
System.out.println(u.getName());
System.out.println(u.getPassword());
if(u.getName().trim().equalsIgnoreCase("zx")&&u.getPassword().equals("zx"))
return SUCCESS;
else
return ERROR;
} public User getModel() {
// TODO Auto-generated method stub
return u;
}
}<package name="userLogin" extends="struts-default" namespace="/">这个namespace不加或namespace=""就报错  HTTP Status 404 - No result defined for action com.struts2c.action.LoginAction and result success加个/就好的。怎么我就用不了,默认命名空间?

解决方案 »

  1.   

    <action name="login" class="com.struts2c.action.LoginAction">
                
                    <result type="chain">test</result>
                    <result name="error" type="redirect">/xz.jsp</result>
                </action>你就是没有配置success的啊
      

  2.   

    <package name="userLogin" extends="struts-default" namespace="/"> 这就是默认命名空间啊
      

  3.   

    这个问题是比较纠结的,主要是你用的struts2的版本高,里面对struts2的注解配置做了一些改变,这个你到后面学的时候可能会了解到,现在如果你想把这个问题解决的话,可以查看一下你放action类的包我名字里面是否含有struts或struts2或action或actions中的一个或多个单词,如果 有的话就把包名重新命名下,不让有这几个单词就ok了!
      

  4.   

     <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>*.jsp</url-pattern>
            <dispatcher>REQUEST</dispatcher>
            <dispatcher>FORWARD</dispatcher> 
     </filter-mapping> 
     <filter-mapping>
      <filter-name>Struts2</filter-name>
            <url-pattern>*.action</url-pattern>
            <dispatcher>REQUEST</dispatcher>
            <dispatcher>FORWARD</dispatcher> 
     </filter-mapping>