---
title: "struts问题1"
author: "qdujunjie"
date: "2009-11-19T15:50:20Z"
tags: ["Apache", "JSP", "Java", "Servlet", "Struts"]
slug: "struts-1"
draft: false
lastmod: "2009-11-19T15:52:37Z"
id: 520458
url: "https://qdujunjie.iteye.com/blog/520458"
---

今天刚开始看struts，碰到了一个这样的问题：

 

 The server encountered an internal error () that prevented it from fulfilling this request.

搜索了网上，各种回答都有，但是没有一个符合我的问题。结果到最后自己找到了问题所在。其实很简单，就是配置错了

 

struts-config.xml

 

中的Action的path。

 

我是按照书上的一个猜数字的示例程序来做的。

 

需要两个ActionForm和两个Action。分别是：

 

ActionForm是：

 

createNumberActionForm

judgeActionForm

 

Action是：

 

createNumberAction

judgeAction

 

 

然后一个入口文件guess.jsp。guess.jsp中的表单部分的action是这样的：

 

  &lt;html:form method="POST" action="/createNumberAction.do"&gt;  
  &lt;/html:form&gt;

 

结果运行guess.jsp时，就出现了这样的错误：

 

 

 

**type** Exception report

**message**

**description** The server encountered an internal error () that prevented it from fulfilling this request.

**exception**

```
javax.servlet.ServletException: Cannot retrieve mapping for action /createNumberAction
	org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:848)
	org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:781)
	org.apache.jsp.guess_jsp._jspService(org.apache.jsp.guess_jsp:82)
	org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
	org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:322)
	org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:291)
	org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
```

 

**root cause**

```
javax.servlet.jsp.JspException: Cannot retrieve mapping for action /createNumberAction
	org.apache.struts.taglib.html.FormTag.lookup(FormTag.java:753)
	org.apache.struts.taglib.html.FormTag.doStartTag(FormTag.java:443)
	org.apache.jsp.guess_jsp._jspx_meth_html_form_0(org.apache.jsp.guess_jsp:165)
	org.apache.jsp.guess_jsp._jspx_meth_html_html_0(org.apache.jsp.guess_jsp:124)
	org.apache.jsp.guess_jsp._jspService(org.apache.jsp.guess_jsp:73)
	org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
	org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:322)
	org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:291)
	org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
```

 

**note** The full stack trace of the root cause is available in the Apache Tomcat/5.5.9 logs.

 

 

 

这么一堆东西，根本找不到头绪，不过其中有一句还是挺重要的：

 

Cannot retrieve mapping for action /createNumberAction

很明显没找到/createNumberAction这个Action。

 

因为只可能从struts-config.xml这个配置文件中找Action，所以肯定是这里有问题，一看，果然没有createNumberAction，我用向导创建了Action之后，在配置文件中使这个样子:

 

    &lt;action  
      attribute="createNumberActionForm"  
      name="createNumberActionForm"  
      path="/createNumber"  
      type="com.yourcompany.struts.action.CreateNumberAction"  
      validate="false" /&gt;

 

对，就是path写错了，应该是我们要找的/createNumberAction这个才对，换成/createNumberAction，然后重新上传访问，结果就OK了！

 

也就是说，配置文件中的action的path必须和前台的使用了struts标签的表单的action的路径对应起来。