- From: Guido Paschke <wgp031@rzserv2.fh-lueneburg.de>
- Date: Thu, 26 Nov 1998 23:08:31 +0100
- To: www-jigsaw@w3.org
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hi, my questions concerns the following: I'm writing a simple servlet that's reading an HTML document and inserts a style sheet url after the <head> element. The servlet works fine for the first request but the following requests are corrupted . The servlet log says that the servlet is initializing and the jigsaw log says: 193.174.33.99 - - [25/Nov/1998:11:09:16 +0] "GET http://193.174.33.99:8001/servlets/insertStyleSheet HTTP/1.1" 1001 -1 What does 1001 mean ?? In the RFC2068 (HTTP1.1) 1001 is not defined. Ok here's the servlet code (the code is very alpha and I`don`t think very good...) :-(( /* insertStyleSheet.java erstellt: 21/11/98 Author : Guido Paschke History : Version : 0.2 servlet Parameter: inputHtml : zu parsende HTML Datei (abs. oder rel. Pfad) !!! Pfadtrenner beachten: / oder \\ !!! styleSheetUrl : URL des einzufügenden Style Sheets in der Form <http://...> */ import java.lang.*; import java.io.*; import java.util.*; import javax.servlet.*; import javax.servlet.http.*; public class insertStyleSheet extends HttpServlet { private boolean beginHtml = false; private int charFromSource, charFromStyle; private char beginHtmlTag = '<'; private char endHtmlTag = '>'; private String beginHeadTag = new String("<head>"); private StringBuffer parseHtml = new StringBuffer(); private String styleConstruct; private File inputFile; private BufferedReader readHtml; public void init(ServletConfig config) throws ServletException { super.init(config); if(checkInitParameter()) { styleConstruct = new String ("\n<LINK rel=\"stylesheet\" HREF=\"" + getInitParameter("styleSheetUrl") + "\">"); try { inputFile = new File(getInitParameter("inputHtml")); readHtml = new BufferedReader(new FileReader(inputFile)); } catch (FileNotFoundException e) { System.err.println("insertStyleSheet: " + e); } catch (IOException e) { System.err.println("insertStyleSheet: " + e); } } else throw new UnavailableException (this, "Parameter falsch oder fehlend !!"); } public void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { PrintWriter out; // set content type and other response header fields first response.setContentType("text/html"); // then write the data of the response out = response.getWriter(); try { while ((charFromSource = readHtml.read()) != -1) { System.out.print((char) charFromSource); // debug out.write(charFromSource); if(((char) charFromSource) == beginHtmlTag) beginHtml = true; if(beginHtml) parseHtml.append((char) charFromSource); if(((char) charFromSource) == endHtmlTag) { if(parseHtml.toString().toLowerCase().compareTo(beginHeadTag) == 0) { System.out.print(styleConstruct); // debug out.print(styleConstruct); } parseHtml.setLength(0); beginHtml = false; } } } catch (IOException e) { System.err.println("insertStyleSheet: " + e); } } public String getServletInfo() { return "Servlet to automatically insert a style sheet link"; } public void destroy() { // do to : code gets here try { readHtml.close(); } catch (IOException e) { System.err.println("insertStyleSheet: " + e); } } private boolean checkInitParameter() { if (getInitParameter("inputHtml") == null) { System.err.println("Fehlende oder falscher Parameter: inputHtml !!"); return false; } else if (getInitParameter("styleSheetUrl") == null) { System.err.println("Fehlende oder falscher Parameter: styleSheetUrl !!"); return false; } return true; } } /*** eof: insertSstyleSheet.java ***/ thanx in advance Guido Paschke -----BEGIN PGP SIGNATURE----- Version: PGPfreeware 5.5.3i for non-commercial use <http://www.pgpi.com> iQA/AwUBNl3DT44cxP/6mVV/EQIsrgCcDn+33vol7xt+CVNUgi1qwkuCLLEAnjMR BqthB2Yy1S+cgqvvGOcA8frm =VlZZ -----END PGP SIGNATURE----- ------ begin sig ------ Guido Paschke @ Fachhochschule Nordostniedersachsen FB Wirtschaft Email: wgp031@rzserv2.fh-lueneburg.de Valid PGP-key at cl6.fh-lueneburg.de port: 11371 ****** Trust only signed Emails !!! ******* ----- end sig ---------
Received on Thursday, 26 November 1998 17:08:43 UTC