facebook

servlet doGet() method

  1. MyEclipse IDE
  2.  > 
  3. Off Topic
Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #260484 Reply

    Bobby
    Member

    Hi:

    Here is the piece of code:

    public void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {

    private boolean lineBreak = true;

    response.setContentType(“text/html”);
    PrintWriter out = response.getWriter();
    out
    .println(“<!DOCTYPE HTML PUBLIC \”-//W3C//DTD HTML 4.01 Transitional//EN\”>”);
    out.println(“<HTML>”);
    out.println(” <HEAD><TITLE>A Servlet</TITLE></HEAD>”);
    out.println(” <BODY>”);
    out.print(” This is “);
    out.print(new java.util.Date());
    out.println(“, using the GET method along with new text”);
    display(request, response);
    out.println(” </BODY>”);
    out.println(“</HTML>”);
    out.flush();
    out.close();
    }

    In the above code where it says “private boolean lineBreak = true;”, i get an error in myeclipse stating that “illegal parameter for lineBeak; only final is permitted”

    I would like to know why it says only final is permitted; can’t i use a non-final variable in doGet() method?

    Thanks in advance!!!
    Bhavin

    #260490 Reply

    Riyad Kalla
    Member

    Bhavin,
    You are declaring your variable inside of a method, it is already method-scoped, you cannot use any visibility modifiers like private/public/etc. *inside* of a method. Final is the only modifier allowable which declares that the value of the variable will never change, I doubt you want that. It should just be:
    boolean lineBreak = true;

    #260849 Reply

    Bobby
    Member

    Thanks, Riyaz. I

Viewing 3 posts - 1 through 3 (of 3 total)
Reply To: servlet doGet() method

You must be logged in to post in the forum log in