日期:2014-05-17  浏览次数:21164 次

关于struts2的There is no Action mapped for namespace / and action name login.
一个简单的登录验证,不多说,直接贴代码:
login.jsp

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>

<%@ taglib uri="/struts-tags" prefix="s" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>登录</title>
  </head>
  
  <body>
   <div>
    <center>
    <s:form action="/login.action" method="post">
    <!-- 账户输入框 -->
    <s:textfield name="userno" label="账号"></s:textfield>
<!-- 密码输入框 -->
<s:password name="password" label="密码"></s:password>
<!-- 确定与重置按钮 -->
<s:submit value="确定"></s:submit>
<s:reset value="重置"></s:reset>
    </s:form>
    <!-- 注册新用户链接 -->
    <a href="regist.jsp">注册新用户</a>
    </center>
   </div>
  </body>
</html>


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>
  
  <!-- 设置srtuts2框架的 -->
  <filter>
   <filter-name>struts2</filter-name>
   <filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
  </filter>
  
  <filter-mapping>
   <filter-name>struts2</filter-name>
   <url-pattern>/*</url-pattern>
  </filter-mapping>
</web-app>


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">