java吧 关注:1,273,038贴子:12,784,538
  • 4回复贴,共1

有段很好玩的程序

只看楼主收藏回复

import javax.servlet.*;
import javax.servlet.http.*;
   // other imports

  public class TemplateServlet extends HttpServlet
{

  public void init(){// called once when servlet created} 
  public void destroy(){// called once when servlet unloaded}

 public void doGet(HttpServletRequest request, HttpServletResponse
   response)throws IOException, ServletException;
    {  // Handle a GET request here }
 public void doPost(HttpServletRequest request,HttpServletResponse
   response)throws IOException,ServletException;
     {// Handle a POST request here  }
  // other methods
}
  import java.io.*;
  import javax.servlet.*;
  import javax.servlet.http.*;

  public class HelloWorld extends HttpServlet
 {
  public void doGet(HttpServletRequest request,
    HttpServletResponse response)
    throws IOException,ServletException
    {
     response.setContentType("text/html");
     PrintWriter out = response.getWriter();
     out.println
     ("<html>\n"+"<head>\n"+"<title>HelloWorld</title>\n"+
     "</head>\n"+"<body>\n"+"<h1>HelloWorld</h1>\n" +
     "< /body> \n" + " < /html> \n");
     out.close();
 
    }     
}  

各位高手大哥..救命啊..刚弄了一段代码..调试两小时了老是错..能告诉我该怎么改吗..感激不禁!!@
    第九行老是被认为"非法表达式"很郁闷啊..


1楼2007-10-22 02:31回复
    很可能语句前面有非法字符(你在记事本里面编辑,把每行语句的前导空格全部去掉,然后编译看看)


    2楼2007-10-22 08:47
    回复
      2025-08-07 22:33:21
      广告
      不感兴趣
      开通SVIP免广告
      • 219.136.212.*
      public void doGet(HttpServletRequest request, HttpServletResponse
       response)throws IOException, ServletException;
       { 

      这里的';'


      4楼2007-10-22 10:08
      回复
        调试了...貌似还和原来的错误一样啊...不明白了


        5楼2007-10-22 13:03
        回复
          public void doGet(HttpServletRequest request, HttpServletResponse
           response)throws IOException, ServletException;
           { // Handle a GET request here }
           public void doPost(HttpServletRequest request,HttpServletResponse
           response)throws IOException,ServletException;
           {// Handle a POST request here } 

          doGet,doPost都有问题:"ServletException;"这个';'号多余的;"{// Handle a POST request here } ",这句把'}'给注释掉了,也就是说没有'}'了.


          IP属地:广东6楼2007-10-22 14:16
          回复