`
zhyl2010
  • 浏览: 11767 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
最近访客 更多访客>>
社区版块
存档分类
最新评论

解决STRUTS2 错误 There is no Action mapped for namespace / and action name login

阅读更多
使用MyEclipse8.5 + tomcat6.0进行开发。
这是一个登录验证程序。 
已经把structs资源包中的blank项目中的jar放到myeclipse的lib目录中 
代码部分见下 
错误信息 
严重: Could not find action or result 
There is no Action mapped for namespace / and action name login. - [unknown location]  ......
===================================================================
  /**********************以下为代码和配置文件**********************/
===================================================================
LoginAction.java程序如下:
package com.struts.action;

public class LoginAction {

private String username;
private String password;

public String getUsername() {
return username;
}

public void setUsername(String username) {
this.username = username;
}

public String getPassword() {
return password;
}

public void setPassword(String password) {
this.password = password;
}

public String execute() {
if (username.trim().equals("www") && (password.equals("www"))) {
return "success";
} else {
return "failed";
}
}
}
===============================================================
index.jsp文件代码如下:
<body>
<center>
<h1 align="center">
用户登录
</h1>
<form action="login.action" method="post">
姓名:
<input type="text" name="username" />
<br>
密码:
<input type="text" name="password" />
<br>
<br>
<br>
<input type="submit" name="submit" value="登录" />
</form>
</center>
</body>
================================================================
success.jsp和failed.jsp代码非常相似,如下:
success.jsp
<body>
<h1>欢迎登录!</h1>
</body>
failed.jsp
<body>
<h1>
登录失败!
</h1>
<a href="index.jsp">返回</a>
</body>
================================================================
其中struts.xml配置如下:
<struts>
<package namespace="" name="login" extends="struts-default">
<action name="login" class="com.struts.action.LoginAction">
<result name="success">/success.jsp</result>
<result name="failed">/failed.jsp</result>
</action>
</package>
</struts>
=================================================================
web.xml配置如下:
<filter>
<filter-name>struts</filter-name>
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
</filter>
<filter-mapping>
<filter-name>struts</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
=================================================================
  /*******************一下为解决方法****************************/
=================================================================
刚开始时,输入用户名和密码点击登录按钮时,就会显示http;status 404错误,There is no Action mapped for namespace / and action name login,经过仔细观察,解决方法如下:
1.将struts.xml一定要放在src目录下,这样在程序编译时,就会将其放到classes目录下。
2.一定要将struts.xml中的extends="struts-default"写正确,刚开始的时候,把default写成了dafult,最后经过改正,程序可以正常运行了!
3.插一句,namespace写不写都影响不大的。
一定要注意以上红色字体和蓝色字体部分,这个是程序能否正常运行的关键!!!
分享到:
评论
3 楼 zhyl2010 2012-08-16  
落雪封 写道
仍然过不去啊!还是那个错误

你再仔细看看,不知道是不是struts版本的问题,我用的都是2.2以上的
2 楼 落雪封 2012-01-25  
仍然过不去啊!还是那个错误
1 楼 zudajun225 2011-09-08  
我下了一个struts2.1.8,然后就开始做一个Helloworld程序,接着就发生了There is no Action mapped for namespace / and action name的异常,我很纳闷,然后到百度上搜了一下,发现铺天盖地的都是这个异常,长达4页多,但是都没能解决我的问题。经过研究,我终于发现异常产生的原因,非常兴奋,由于用文字难以表述这个异常,于是我特别为这个异常录制了一集28分钟的视频,这个异常非常有意思。如果谁遇到了这个异常,而你又不知道为什么,那么请留下联系方式,我会将这个28分钟的视频传给你,里面清楚的阐述了异常的原因,以及如何避免这个异常的产生。最好留下QQ号码,如果email的话,怕传不了,视频大小30M。你也可以加这个QQ号码:215498544,我会把视频传给,你会发现这是个非常有意思的异常。
视频下载地址:http://download.csdn.net/detail/zudajun225/3581893

相关推荐

    一个struts2的例子:彻底解决STRUTS2 错误There is no Action mapped for namespace / and action name login

    前几天在网上下载一个struts2的helloword的例子,那个作者也真够缺德的,搞个错误的程序,害得我查了一天的程序错误。 最后发现竟然是struts.xml被写成啦sturts.xml。 碰见这样的问题先鄙视下提供例子的作者, 再...

    HTTP Status 404 - There is no Action

    HTTP Status 404 - There is no Action mapped for namespace and action name BackMemberGroupAudit..doc

    weblogic安装部署以及常见问题解决

    该文档对weblogic使用过程中,包括下载,安装,部署...6. weblogic部署war包action不能访问问题解决方法 [There is no Action mapped for namespace / and action name]. 5 7. java.lang.StackOverflowError. 5 等等

    解决使用struts2 时 访问web工程首页问题

    http://localhost:8080/ struts2会拦截,出现异常信息 There is no Action mapped for namespace / and action name.默认配置的welcomefile没有起作用。 按附件配置即可解决此问题

    struts2 HelloWord例字

    在网上找了好个struts2的例子结果都不好使报There is no Action mapped for namespace / and action name这个错,没办法自己搞了个好用的,myeclipse 6.0 +tomcat5.5 + jdk 1.5 引入项目后直接发布就可以了!

    外文翻译 stus MVC

    There is no flow logic, no business logic, and no model information -- just tags. Tags are one of the things that make Struts unique compared to other frameworks like Velocity. Note: "Think thin" ...

    MDB: A Memory-Mapped Database and Backend for OpenLDAP

    MDB: A Memory-Mapped Database and Backend for OpenLDAP

    微软内部资料-SQL性能优化2

    To reserve or commit memory and unintentionally not release it when it is no longer being used. A process can leak resources such as process memory, pool memory, user and GDI objects, handles, threads...

    struts_2.3.12GA_API文档(chm版本)

    Stops the action invocation immediately (by throwing a PauseException) and causes the action invocation to return the specified result, such as Action.SUCCESS, Action.INPUT, etc. void ...

    acpi控制笔记本风扇转速

    is larger than the largest known FADT version, and 2) if there is a mismatch between a 32-bit block address and the 64-bit X counterpart (when both are non-zero.) Example Code and Data Size: These ...

    Memory-Mapped Files for Qualcomm Brew

    Memory-Mapped Files for Qualcomm Brew By Ray Rischpater

    Lie Groups for 2D and 3D Transformations

    This document derives useful formulae for working with the Lie groups that represent transformations in 2D and 3D space. A Lie group is a topological group that is also a smooth manifold, with some ...

    Ambiguous mapping. Cannot map *** method 报错解决

    开发中,我们常常会遇到很多异常报错,现在就我工作中经常遇到...解决:修改请求方式 或 修改请求地址 补充:遵循 RESTful API的开发风格,就算 api地址一样,只要 RequestMapping 请求类型相同,是不会报错的。 详情看

    SSD7 选择题。Multiple-Choice

    When mapping from an ER model to a relational model, a strong entity is mapped into a (a) table (b) row (c) column (d) key Correct answer is (a) 10. Which of the following is true about ...

    Fixed comparing against disconnected mapped network drives to pr

    Fixed comparing against disconnected mapped network drives to prompt for username/password and reconnect.

    操作系统(内存管理)

    /* It is no longer available */ current_location_mcb-&gt;is_available = 0; /* We own it */ memory_location = current_location; /* Leave the loop */ break; } } /* If we made...

    Qemu-1.0.1 for windows

    string1 sets the window title and string2 the process name (on Linux) -uuid x-x-x-x-2x specify machine UUID Display options: -display sdl[,frame=on|off][,alt_grab=on|off][,ctrl_grab=on|off] [,...

    MemoryMappedFile 使用 共享内存循环读写

    MemoryMappedFile 使用 C# 内存中分配一大块地址. 前边分配一个用与共同配置用 后边N个结构体 for循环建 一般用到此问题,两本程序 一个读一个写 循环读写 ----2015/09/24 Lyndon 上海----

    Simulating planar reflection using two-pass rendering and texture mapping

    3. There is a point light and a single directional light in the scene. 4. There is one rotating triangle floating in the air, casting a shadow on the table, walls and other objects. 5. The program ...

    Vector CANdb++ SP27 CAN报文编辑软件

    For a node's Mapped Rx signal, the assigned value table is displayed in the dialog box in addition to the overview. For user-defined attributes with the type "hex" it is now possible to define the min...

Global site tag (gtag.js) - Google Analytics