login.jsp <form action="login.action" method="post">
username:<input type = "text" name = "username" > <br>
password:<input type = "password" name = "password"> <br>
<input type =  "submit" value = "submit">result.jsp
username:${requestScope.username} <br>
password:${requestScope.password} LoginAction:
package com.test.Action;public class LoginAction { private String username;
private String password;
public void setPassword(String password) {
this.password = password;
}
public String getPassword() {
return password;
}
public void setUsername(String username) {
this.username = username;
}
public String getUsername() {
return username;
}


public String execute() throws Exception
{
return "success";
}
}
structs.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.0.dtd">
    
    
    <struts>
     <package name="struts2" extends="struts-default">
     <action name="login" class = "com.test.Action.LoginAction">
     <result>/result.jsp</result>
     </action>
     </package>
   
    </struts>web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<filter>
<filter-name>strcuts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>strcuts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>报的错:
description The requested resource (There is no Action mapped for namespace / and action name login.) is not available.

解决方案 »

  1.   

    structs.xml: ?
    <filter>
    <filter-name>struts2</filter-name>
    <filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
    <init-param>
    <param-name>struts.i18n.encoding</param-name>
    <param-value>UTF-8</param-value>
    </init-param> </filter>
      

  2.   

    <form action="login.action" namespace="" method="post"> 
      

  3.   

    貌似你struts配置文件中没写namespace
      

  4.   

    http://you.video.sina.com.cn/b/28060938-1678505053.html
    我看的这个教程里面没有namespace
    也没有1楼的那个写法
      

  5.   

    楼上的应该是吧,有的是不需要action的,有的是需要的
      

  6.   

    to 楼上<form action="login.action" method="post">  
    换成<form action="login" method="post">也不行
      

  7.   

     楼主 、? 醒醒... 要封装数据就得使用 struts2 的标签呀! 你试一下用:   <s:form action="login.action" method="post"> 
          ........你的代码!
       </s:from>
      

  8.   

    to 楼上http://you.video.sina.com.cn/b/28060938-1678505053.html 
    这个教程没用struts2标签也运行了
      

  9.   

    requested 配置文件有问题 
      

  10.   

    to 楼上username:${requestScope.username} <br>
    password:${requestScope.password} 这两行删除了也不行
      

  11.   

    重启下服务器。
    我按你代码测试过没问题。。
    只是发现使用
    org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter 
    会乱码
    使用1L的
    <filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
    这比较好。。
      

  12.   

    <form action="login.action" method="post">
    username: <input type = "text" name = "username" > <br>
    password: <input type = "password" name = "password"> <br>
    <input type =  "submit" value = "submit"> 
    </form>  //这东西忘掉了吧
      

  13.   

    真怪了。你可以运行。为什么我不行呢。我重新安装了tomcat 5.0  6.0  都不行
      

  14.   

    你应该是没把struts.xml放在scr下
      

  15.   

      <action name="login" class = "com.test.Action.LoginAction"> 
      <action name="/login" class = "com.test.Action.LoginAction"> 
      

  16.   

    根据你报错的信息来说:
    没找你你的action。看你上面的代码和namespace 没关系。
    struts也没写错。。
    应该就是你位置问题了
      

  17.   

    你应该是没把struts.xml放在scr下 
    ???