(急,在线等)请教servlet问题
我写了个servlet.java,编译后把它放在C:\Tomcat 5.0\webapps\shop\WEB-INF\classes\com\shop下,然后在jsp文件中写 <form id= "form1 " name= "form1 " method= "post " action= "FormAction "> ,为什么运行后显示The requested resource (/shop/com/shop/FormAction) is not available.
,请高手指点一下,谢谢
package com.shop;
import java.io.IOException;
import java.util.Collection;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* Servlet implementation class for Servlet: UserListServlet
*/
public class FormAction extends javax.servlet.http.HttpServlet implements
javax.servlet.Servlet
{
/*
* (non-Java-doc)
*
* @see javax.servlet.http.HttpServlet#HttpServlet()
*/
public FormAction()
{
super();
}
/*
* (non-Java-doc)
*
* @see javax.servlet.http.HttpServlet#doGet(HttpServletRequest request,
* HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException
{
response.setHeader( "Pragma ", "No-cache ");
response.setHeader( "Cache-Control ", "no-cache ");
response.setDateHeader( "Expires ", 0);
String name = request.getParameter( "name ");
int age = Integer.parseInt(request.getParameter( "age "));
System.out.println ( "name= "+name);
System.out.println ( "age= "+age);
System.out.println( "ok ");
}
}
[解决办法]
form id= "form1 " name= "form1 " method= "post " action= "FormAction "> ,
把post改成get看看
[解决办法]
你得在web.xml里配置servlet啊
<web-app>
<servlet>
<servlet-name> FormAction </servlet-name>
<servlet-class> com.shop.FormAction </servlet-class>
</servlet>
<servlet-mapping>
<servlet-name> FormAction </servlet-name>
<url-pattern> /FormAction </url-pattern>
</servlet-mapping>
</web-app>
[解决办法]
还有 把你的formaction改成你的servlet类名!!
[解决办法]
alieneagle() 正解,顶!!!
[解决办法]
顶一个!!!!!!!!