There is no Action mapped for namespace [/] and action name [Login] associated with context path [/e

來源:互聯網
上載者:User

標籤:des   style   class   blog   code   java   

近期學習web開發時,就遇到這個令人頭疼的問題。

百度Google了N遍,最終在部落格http://blog.csdn.net/liu578182160/article/details/17266879中找到了問題的根源。

開發環境:win7 32位旗艦版,jdk1.7_45,jre7,eclipse4.3.1 JavaEE版,tomcat 7.0.42,struts2.3.16.3


問題出如今web.xml配置

原web.xml:

<?xml version="1.0" encoding="UTF-8"?><web-app id="struts2Demo" 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>struts2</filter-name>        <filter-class>        org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter        </filter-class>    </filter>    <filter-mapping>        <filter-name>struts2</filter-name>        <url-pattern>/*</url-pattern>    </filter-mapping></web-app>

改動後的web.xml:

<?xml version="1.0" encoding="UTF-8"?>  <web-app version="3.0"       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_3_0.xsd">    <display-name></display-name>          <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>/*</url-pattern>    </filter-mapping>        <welcome-file-list>      <welcome-file>login.jsp</welcome-file>    </welcome-file-list>  </web-app>

關鍵的差別就在於web-app的version

(似乎不關這版本號碼問題,剛試了2.4的web-app,能夠執行成功。)


可能這不是問題的關鍵,項目改動的地方還有

原login.jsp:

<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%><%String path = request.getContextPath();String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html>  <head>    <base href="<%=basePath%>">        <title>My JSP 'login.jsp' starting page</title>    <meta http-equiv="pragma" content="no-cache"><meta http-equiv="cache-control" content="no-cache"><meta http-equiv="expires" content="0">    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"><meta http-equiv="description" content="This is my page"><!--<link rel="stylesheet" type="text/css" href="styles.css">-->  </head>    <body>    <form action="login.action" method="post"><!-- login就是struts.xml裡的action的name -->    使用者名稱<input type="text" name="username" />  <!-- username相應LoginAction的username通過set方法傳入 -->        密碼: <input type="password" name="password" /> <!-- password相應LoginAction的password通過set方法傳入 -->    <input type="submit" name="Submit" value="Submit"/>    </form>  </body></html>

改動後的login.jsp:

<%@ page language="java" contentType="text/html; charset=UTF-8"    pageEncoding="UTF-8"%><%@taglib prefix="s" uri="/struts-tags" %><!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title><s:text name="loginPage"/></title></head><body><s:form action="login"><s:textfield name="username" key="user"/><s:textfield name="password" key="pass"/><s:submit key="login" value="Submit"/></s:form></body></html>


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.