当前位置: 代码迷 >> Java Web开发 >> 刚学struts就遇到问题
  详细解决方案

刚学struts就遇到问题

热度:162   发布时间:2007-01-16 15:45:04.0
刚学struts就遇到问题

刚学struts就遇到问题,那位高手能给我看看,在线等
+++++++++++++++++++++++++++++++++++++++++++++++++++++
报的错误
HTTP Status 500 -

--------------------------------------------------------------------------------

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 /HelloWordAction
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:825)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:758)
org.apache.jsp.HelloWord_jsp._jspService(HelloWord_jsp.java:103)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)


root cause

javax.servlet.jsp.JspException: Cannot retrieve mapping for action /HelloWordAction
org.apache.struts.taglib.FormTag.lookup(FormTag.java:810)
org.apache.struts.taglib.FormTag.doStartTag(FormTag.java:506)
org.apache.jsp.HelloWord_jsp._jspx_meth_html_form_0(HelloWord_jsp.java:120)
org.apache.jsp.HelloWord_jsp._jspService(HelloWord_jsp.java:89)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)


note The full stack trace of the root cause is available in the Apache Tomcat/5.0.28 logs.
+++++++++++++++++++++++++++++++++++++++++++++++++++++
页面
<!-- Copyright (c) 2002 by ObjectLearn. All Rights Reserved. -->
<%@ page language="java" pageEncoding="GB2312" %>
<%@taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@taglib uri="/WEB-INF/struts-html.tld" prefix="html"%>
<%@taglib uri="/WEB-INF/struts-logic.tld" prefix="logic"%>
<%@ taglib uri="/WEB-INF/struts-template.tld" prefix="template" %>
<jsp:useBean id="HelloWordForme"class="web.form.HelloWordForm"scope="page"/>
<html>
<head>
<title> Hello Word </title>
</head>
<body>
<html:form action="/HelloWordAction"method="post">
请输入:Hello Word:<html:text property="word"/><html:submit/>
</html:form>
<br>
+++++++++++++++++++++++++++++++++++++++++++++++++++++
config中配置
<?xml version="1.0" ?>
<!DOCTYPE struts-config PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 1.1//EN"
"http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd">
<struts-config>
<form-beans>
<form-bean name="HelloWordForm" type="web.form.HelloWordForm"/>

</form-beans>
<global-exceptions/>

<global-forwards/>
<action-mappings>
<action path = "/HelloWordAction"
type= "web.action.HelloWordAction"
name="HolloWordForm"
validate="false"
scope="session"
>
<forward name="success" path="/index.jsp"/>
</action>
</action-mappings>
<controller/>

<message-resources parameter="ApplicationResources"/>
</struts-config>


<bean:write name="HelloWordForme" scope="session" property="word"/>
</body>
</html>

搜索更多相关主题的帖子: struts  

----------------解决方案--------------------------------------------------------

action 和form的代码呢?


----------------解决方案--------------------------------------------------------
[CODE][QUOTE]

action内容
package web.action;


import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
public class HelloWordAction extends Action {
public ActionForward execute(ActionMapping mapping,ActionForm form,HttpServletRequest request,HttpServletResponse response)

throws Exception
{
return mapping.findForward("success");
}
}

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++


----------------解决方案--------------------------------------------------------
你的配置文档怎么写到页面里面去了??
----------------解决方案--------------------------------------------------------
<html:form action="/HelloWordAction"method="post">
请输入:Hello Word:<html:text property="word"/><html:submit/>
</html:form>

注意你的HelloWordAction这个是什么,这里应该使用HelloWordAction。do之类的

请查看Struts的相关文档


----------------解决方案--------------------------------------------------------
<!-- Copyright (c) 2002 by ObjectLearn. All Rights Reserved. -->
<%@ page language="java" pageEncoding="GB2312" %>
<%@taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@taglib uri="/WEB-INF/struts-html.tld" prefix="html"%>
<%@taglib uri="/WEB-INF/struts-logic.tld" prefix="logic"%>
<%@ taglib uri="/WEB-INF/struts-template.tld" prefix="template" %>
<jsp:useBean id="HelloWordForme"class="web.form.HelloWordForm"scope="page"/>
<html>
<head>
<title> Hello Word </title>
</head>
<body>
<html:form action="HelloWordAction.do"method="post">
请输入:Hello Word:<html:text property="word"/><html:submit/>
</html:form>
<br>
<bean:write name="HelloWordForme" scope="session" property="word"/>
</body>
</html>
换成这个也是又错误
----------------解决方案--------------------------------------------------------

form在者
import org.apache.struts.action.ActionForm;

public class HelloWordForm extends ActionForm{

String word="";

/**
* @return 返回 word。
*/
public String getWord() {
return word;
}
/**
* @param word 要设置的 word。
*/
public void setWord(String word ) {
this.word=word;
}
}


----------------解决方案--------------------------------------------------------
是不是没配置web.xml啊
----------------解决方案--------------------------------------------------------

web-xml:
<?xml version="1.0" encoding="UTF-8"?>


<web-app>
<display-name>HelloApp Struts Application</display-name>

<!-- Standard Action Servlet Configuration -->
<servlet>
<servlet-name>action</servlet-name>
<servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
<init-param>
<param-name>config</param-name>
<param-value>/WEB-INF/struts-config.xml</param-value>
</init-param>
<load-on-startup>2</load-on-startup>
</servlet>

<!-- Standard Action Servlet Mapping -->
<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>

<!-- The Usual Welcome File List -->
<welcome-file-list>
<welcome-file>HelloWord.jsp</welcome-file>
</welcome-file-list>

<!-- Struts Tag Library Descriptors -->
<taglib>
<taglib-uri>/WEB-INF/struts-bean.tld</taglib-uri>
<taglib-location>/WEB-INF/struts-bean.tld</taglib-location>
</taglib>

<taglib>
<taglib-uri>/WEB-INF/struts-html.tld</taglib-uri>
<taglib-location>/WEB-INF/struts-html.tld</taglib-location>
</taglib>

<taglib>
<taglib-uri>/WEB-INF/struts-logic.tld</taglib-uri>
<taglib-location>/WEB-INF/struts-logic.tld</taglib-location>
</taglib>

</web-app>


----------------解决方案--------------------------------------------------------
<html:form action="/HelloWordAction.do"method="post">
试试

----------------解决方案--------------------------------------------------------
  相关解决方案