Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / June 2005

Tip: Looking for answers? Try searching our database.

Servlet Compiler Error.

Thread view: 
Steve R. Burrus - 27 Jun 2005 22:25 GMT
I need some help/assistance from one of you able people for always getting a
compiler error indicating that the line[s] "private StringBuffer
getConfigTable(ServletConfig config) {" AND the line  "private StringBuffer
getContextTable(ServletContext context) {" are illegal starts of the
expression! I have tried to do some "workarounds" for this problem but I am
still getting that compiler error. Can anyone please help me with this?
(There MIGHT be one too many ending "}" 's at the bottom of the file, but
other than that what is the problem?

/* Well here I go again with tryin' my hand at creating a new servlet.
Incidentally, this  particular servlet will be called the
*"ContainerServlet.java".
*/

                       package org.steve.burroughs;

                       import javax.servlet.*;
                       import javax.servlet.http.*;
                       import java.io.*;
                       import java.util.*;

public class ContainerServlet extends GenericServlet  {
 public void service( ServletRequest request, ServletResponse response)
throws
                        ServletException, IOException {
    StringBuffer configTable = getConfigTable(getServletConfig() ) ;
    StringBuffer contextTable = getContextTable(getServletContext() ) ;
       response.setContentType( "text/html" );
         PrintWriter steve = response.getWriter();

         steve.println("<html><head><title>Why Can\'t I Get "+
"Screwed??</title><head><body>");
         steve.println("<h1>Servlet Configuration Information</h1>" +
configTable + "<hr>");
         steve.println("<h1>Servlet Context Information</h1>" +
contextTable);
         steve.println("</body></html>");
         steve.flush();
         steve.close();

       private StringBuffer getConfigTable(ServletConfig config) {
  HTMLTable table = new HTMLTable ();
  table.appendRow("Servlet Name", config.getServletName( ));
  Enumeration e = config.getInitParameterNames() ;
  while ( e.hasMoreElements() ) {
   String pn = (String)e.nextElement();
   String pv = config.getInitParameter(pn);
   table.appendRow("Parameter : <code> " + pn +
                   "</code>", pv);
     }
      return table.toStringBuffer();
    }

    private StringBuffer getContextTable(ServletContext context) {
     HTMLTable table = new HTMLTable ();
          table.appendTitleRow("Attributes") ;
          Enumeration e = context.getAttributeNames() ;
       while ( e.hasMoreElements() ) {
         String pn = (String)e.nextElement ();
         Object po = context.getAttribute( pn);
         String pv = " " ;
         if( po instanceof String) {
       pv = (String) context.getAttribute( pn);
         } else if ( po instanceof String[]) {
       String[] pa = (String[])context.getAttribute( pn);
       for(int i = 0; i < pa.length; i++){
        pv = pv + pa[i] + "<br>";
          }
         }
         else {
       pv = context.getAttribute( pn).toString();
         }
         table.appendRow("Attribute : <code> " + pn +
                   "</code>", pv);
      }
   }
  }

 }
Wendy Smoak - 27 Jun 2005 23:16 GMT
> I need some help/assistance from one of you able people for always getting a
> compiler error indicating that the line[s] "private StringBuffer
> getConfigTable(ServletConfig config) {" AND the line  "private StringBuffer
> getContextTable(ServletContext context) {" are illegal starts of the
> expression!

You're missing the closing brace for the 'service' method:
     Put a } before "private StringBuffer getConfigTable"

Then delete one of the closing braces at the very end.

(All I did was paste it into JEdit and use the JavaStyle plugin to reformat
the buffer, which popped up a dialog box with the location of the errors.)

Signature

Wendy Smoak



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.