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.
xmlns:xsi="http://www.
xsi:schemaLocation="http://java. http://java.
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>