sign 发表于 2019-9-27 23:18:18

Exception occurred during processing request

本帖最后由 sign 于 2019-9-27 23:26 编辑

一样的代码在朋友电脑上运行通过了但是我的电脑一直报错,求大神帮看下
报错如下
严重: Exception occurred during processing request: There is no Action mapped for namespace [/] and action name associated with context path .
There is no Action mapped for namespace [/] and action name associated with context path . -
      at com.opensymphony.xwork2.DefaultActionProxy.prepare(DefaultActionProxy.java:185)
      at org.apache.struts2.impl.StrutsActionProxy.prepare(StrutsActionProxy.java:63)
      at org.apache.struts2.impl.StrutsActionProxyFactory.createActionProxy(StrutsActionProxyFactory.java:39)
      at com.opensymphony.xwork2.DefaultActionProxyFactory.createActionProxy(DefaultActionProxyFactory.java:58)
      at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:553)
      at org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77)
      at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:99)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:212)
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:94)
      at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:504)
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:141)
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
      at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:620)
      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:509)
      at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1104)
      at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:684)
      at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1524)
      at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1480)
      at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
      at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
      at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
      at java.base/java.lang.Thread.run(Thread.java:835)


代码如下:
package lesson2;

public class User {
      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;
      }

}

package lesson2;
import java.util.Map;
import org.apache.struts2.interceptor.SessionAware;
import com.opensymphony.xwork2.ActionSupport;

public class CCC extends ActionSupport implements SessionAware{


      private static final long serialVersionUID = 1L;
      private User user;
      private Map<String,Object> session;
      
      public String execute()
      {
                session.put("user", user);
                return SUCCESS;
      }

      @Override
      public void setSession(Map<String, Object> session) {
                // TODO Auto-generated method stub
                this.session = session;
      }
      public void setUser(User user)
      {
                this.user = user;
      }
      public User getUser()
      {
                return user;
      }

}
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
                请输入用户名和密码:
      <br>
      <form action="CCC.action" method="post">

      <p>
                用户名:
                <input type="text" name="user.username"/>
      </p>
      <p>
                密码:
                <input type="text" name="user.password"/>
      </p>
      <input type="submit" value="登陆"/>
      </form>

</body>
</html>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
      <p>
                您的用户名为:
                <s:property value="#session.user.username"/>
      </p>
      <p>
                您的密码为:
                <s:property value="#session.user.password"/>
      </p>
</body>
</html>

superbe 发表于 2019-9-28 15:27:49

no Action mapped for namespace [/] and action name associated with context path
看这个提示,可能是struts.xml中Action映射没有配置好,你对比下这个文件。

sign 发表于 2019-9-28 17:05:41

superbe 发表于 2019-9-28 15:27
no Action mapped for namespace [/] and action name associated with context path

这个代码如下<?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="login" namespace="" extends="struts-default">
       <action name="Login" class="lesson2.Login">
                        <result>/welcome.jsp</result>
                </action>
                       
                <action name="AAA" class="lesson2.AAA">
                        <result>/welcomeProperty.jsp</result>
                </action>
               
                <action name="BBB" class="lesson2.BBB">
                        <result>/welcomeModel.jsp</result>
                </action>
               
                <action name="CCC" class="lesson2.CCC">
                        <result>/welcomeSession.jsp</result>
                </action>
               
    </package>
</struts>

我是直接复制了前面运行成功了的BBB改成了CCC,感觉应该没写错,麻烦再帮我看看谢谢

superbe 发表于 2019-9-29 00:17:06

本帖最后由 superbe 于 2019-9-29 11:36 编辑

访问使用的url对吗,在web.xml中 <welcome-file-list> 有没有加入/indexSession.jsp (按你的首页修改)

sign 发表于 2019-9-29 14:36:22

superbe 发表于 2019-9-29 00:17
访问使用的url对吗,在web.xml中有没有加入/indexSession.jsp (按你的首页修改)

没有欸,web.xml原本是这样的:<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<display-name>Struts</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.html</welcome-file>
</welcome-file-list>

</web-app>
我刚刚尝试加了/indexSession.jsp和把html改成jsp但是依旧不行{:5_100:}

sign 发表于 2019-9-29 16:14:42

superbe 发表于 2019-9-29 00:17
访问使用的url对吗,在web.xml中有没有加入/indexSession.jsp (按你的首页修改)

我重装eclipse后把代码复制过去又可以正常运行了。。。可能是之前eclipse有问题,谢谢啦
页: [1]
查看完整版本: Exception occurred during processing request