日期:2014-05-17  浏览次数:20674 次

servlet的有关问题,,会的请答,,
Java code

package Conn;

import java.io.IOException;
import java.io.PrintWriter;

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


public class Test extends HttpServlet {


/**
* The doPost method of the servlet. <br>16:14 2012/7/31
* This method is called when a form has its tag value method equals to post.
* 
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void service(HttpServletRequest request, HttpServletResponse response)throws 

ServletException, IOException {
     //处理中文问题
   request.setCharacterEncoding("utf-8");
   response.setContentType("text/html;charset=utf-8");
   System.out.println("start............");
   String username=request.getParameter("username");
   String content=request.getParameter("content");
   //username=new String(username.getBytes("gb2312"),"utf-8");
   PrintWriter out = response.getWriter();
   out.write(username);
   System.out.println("username>>=="+username);
   out.write(content);
   out.flush();
   out.close();
   System.out.println("end");
}

}


以上是我的一个servlet,在dos窗口中编译的时候,总是报错,说找不到包,,,,,为什么呢,,,真是不明白啊。。。。急死了快,,求解答,,谢谢,,帮帮忙。。

------解决方案--------------------
建议把详细的报错信息贴出来
------解决方案--------------------
你好,这是因为找不到servlet包的原因,请在dos下键入命令
set classpath=c:\tomcat\common\lib\servlet.jar;%classpath%
记住c:\tomcat\common\lib\servlet.jar是你的jar包的地址,当然有可能你的不是servlet.jar,可能你的脚servlet-api.jar 之类的,这个你要看你的tomact的lib下的servlet包的名字,这个命令之后,再编译就可以通过了,我试过了,可以的,祝你好运,呵呵
------解决方案--------------------
顶楼上,不清楚直接联系吧
------解决方案--------------------
首先你的明白:Servlet 是用来干嘛的!

推荐你先首先一下概念,这样你也慢慢首先servlet了,出现问题!就知道从那里下手找问题了!

http://www.cnblogs.com/linux2009/articles/1693598.html
------解决方案--------------------
所需要的类放到classpath中指定