S
Steve R. Burrus
I need some help/assistance from one of you able people for always getting a
compiler error indicating that the line "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 + "<br>";
}
}
else {
pv = context.getAttribute( pn).toString();
}
table.appendRow("Attribute : <code> " + pn +
"</code>", pv);
}
}
}
}
compiler error indicating that the line
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 + "<br>";
}
}
else {
pv = context.getAttribute( pn).toString();
}
table.appendRow("Attribute : <code> " + pn +
"</code>", pv);
}
}
}
}