没有针对命名空间/操作名称登录映射的操作

时间:2016-02-07 10:24:08

标签: java struts2 mapping

这是我的动作类

   package actions;
   import com.opensymphony.xwork2.ActionSupport;
   import bean.UserBean;
   public class UserInsert extends ActionSupport {
   private static final long serialVersionUID = 1L;
   public String execute() throws Exception {
   return "success";
   }
   public static void main(String[] org) {
   }
   }

这是index.jsp代码

    <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
        pageEncoding="ISO-8859-1"%>
    <!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=ISO-8859-1">
    <title>Developer</title>
    </head>

<body>
    <h1>Login Page</h1>
    <form action="login">
        <table>
            <tr>
                <td><label>User Name / Email</label></td>
                <td><input type="text" /></td>
            </tr>
            <tr>
                <td><label>Password</label></td>
                <td><input type="password" /></td>
            </tr>
            <tr>
                <td></td>
                <td><button type="submit">Login</button></td>
            </tr>
        </table>
    </form>
</body>
</html>

这是web.xml代码

<?xml version="1.0" encoding="UTF-8"?>
<web-app 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"
    version="3.0">

    <display-name>Struts Blank</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>index.jsp</welcome-file>
    </welcome-file-list>

</web-app>

这是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.0.dtd">
<struts>
    <constant name="struts.devMode" value="true" />
    <package name="default" namespace="/" extends="struts-default">

        <action name="login" class="actions.UserInsert" method="execute">
            <result name="success">/welcome.jsp</result>
        </action>

    </package>

</struts>

我已经关注了mkyoung&#34; http://www.mkyong.com/struts2/there-is-no-action-mapped-for-namespace-and-action-name-youractionname/&#34;但是得到相同的错误,而“struts.devMode”关闭或“struts.devMode”打开时得到相同的错误&#34;没有映射名称空间/和操作名称登录&#34; 如果有人遇到过这个问题,请提出好的建议。 我使用的是JDK 1.8,Apache Tomcat 8。

1 个答案:

答案 0 :(得分:0)

试试这个

您的行动类

 package actions;
 public class UserInsert {

   public String execute(){
      return "success";
   }
 }

<强>的web.xml

有时在web.xml中可能存在与此org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter相关的问题

尝试粘贴这个

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"   xmlns="http://xmlns.jcp.org/xml/ns/javaee"   xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee   http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID"   version="3.1">
<display-name>Struts Example</display-name>
   <welcome-file-list>
     <welcome-file>index.html</welcome-file>
     <welcome-file>index.htm</welcome-file>
     <welcome-file>index.jsp</welcome-file>

   </welcome-file-list>

 <filter>
      <filter-name>struts2</filter-name>
      <filter- class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</fil ter-class>
 </filter>

      <filter-mapping>
         <filter-name>struts2</filter-name>
         <url-pattern>/*</url-pattern>
      </filter-mapping>

 </web-app>