当前位置: 代码迷 >> Java Web开发 >> Servlet actionServlet is not available
  详细解决方案

Servlet actionServlet is not available

热度:470   发布时间:2008-10-19 01:38:42.0
Servlet actionServlet is not available
我用Eclipse工具开发struts时出现了这样的错误:
HTTP Status 404 - Servlet actionServlet is not available

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

type Status report

message Servlet actionServlet is not available

description The requested resource (Servlet actionServlet is not available) is not available.
目录截图如下:

以下是代码:
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_2_5.xsd"
  version="2.5">
  <servlet>
      <servlet-name>actionServlet </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>1 </load-on-startup>
  </servlet>
  <!--处理所有后缀为do的请求-->
    <servlet-mapping>
        <servlet-name>actionServlet </servlet-name>
        <url-pattern>*.do </url-pattern>
    </servlet-mapping>
</web-app>

struts-config.xml:
<?xml version="1.0" encoding="UTF-8" ?>
<struts-config>
  <!--定义formbean-->
  <form-beans>
      <form-bean name="helloWorld" type="com.demo.bean.HelloWorld"/>
  </form-beans>
  <action-mappings>
  <!--定义提交时访问的路径-->
      <action path="/submit" type="com.demo.action.HelloWorldAction" name="helloWorld">
        <forward name="helloWorld" path="/jsp/helloWorld.jsp"/>
      </action>
      <!--定义初次访问的路径-->
      <action path="/input" type="org.apache.struts.actions.ForwardAction" parameter="/jsp/submit.jsp>
      </action>
  </action-mappings>
</struts-config>

HelloWorld.java:
package com.demo.bean;
import org.apache.struts.action.ActionForm;
public class HelloWorld extends ActionForm{
private String helloWorld=null;
public void setHelloWorld(String helloWorld){
this.helloWorld=helloWorld;
}
public String getHelloWorld(){
return this.helloWorld;
}
}

HelloWorldAction.java
package com.demo.action;
import javax.servlet.*;
import javax.servlet.http.*;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionServlet;
import com.demo.bean.HelloWorld;
public class HelloWorldAction extends Action{
public ActionForward execute(ActionMapping mapping,ActionForm form,HttpServletRequest request,HttpServletResponse response)
throws Exception{
//将页面提交的进行转换成form
HelloWorld helloWorld=(HelloWorld)form;
//将获取的页面内容注入request
request.setAttribute("helloWorld", helloWorld.getHelloWorld());
//返回到helloWorld.jsp页面
return mapping.findForward("helloWorld");
}
}

submit.jsp:
<%@page contentType="text/html;chatset=GBK"%>
<html>
<head> <title>练习使用 </title> </head>
<body>
  <form name="HelloWorld" action="/Demo2/submit.do" method="post">
      请输入要提交的内容: <input type="text" name="helloWorld" avlue=""/> <br>
      <input type="submit" value="提交">
  </form>
</body>
</html>

helloWorld.jsp:
<%@page contentType="text/html;chatset=GBK"%>
<html>
<head> <title>利用struts输出 </title> </head>
<%
  String str=(String)request.getAttribute("helloWorld");
%>
<body>
  <font size='22'> <%=str%> </font>
</body>
</html>
搜索更多相关主题的帖子: Servlet  available  not  

----------------解决方案--------------------------------------------------------
你最好把你的工程传上来 这样太懒得看了
----------------解决方案--------------------------------------------------------
<form name="HelloWorld" action="/Demo2/submit.do" method="post">

这句改成<form name="HelloWorld" action="/submit.do" method="post">
----------------解决方案--------------------------------------------------------
  相关解决方案