You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Eduard Witteveen <Ed...@omroep.nl> on 2001/04/09 11:22:35 UTC
How to parse JSP whithin a Servlet
Hello,
I'm trying to parse a jsp page within my servlet. The reason i want to to that is to use anothor program to parse a script which is generated after parsing the jsp. The parsing should give me back a script, which is used by an external program, after which i will send the result of this external program to the user.
An example(im using it for someting different, but its a good example) of this could be that i have a latex document with jsp tags in the document. After the jsp step, it would give me a latex only document. But i dont want to send this latex document to the users. After i have this latex document, i want to run an external program (nah more then one in this situation (latex *.tex and dvi2ps *.dvi) which will give me back a postscript document.
I tried the following(when this works, i can include my own ServletSesponse class which fills a String):
public synchronized void service(HttpServletRequest req, HttpServletResponse res) throws ServletException,IOException {
javax.servlet.RequestDispatcher dispatcher = getServletContext().getNamedDispatcher("jsp");
if(dispatcher == null) {
log.error("AAARRRGGGG dispatcher was null, please enter a valid name for jsp parser('"+dispatcherName+"')!");
}
dispatcher.include(req, res);
}
(neither include nor forward worked).
public synchronized void service(HttpServletRequest req, HttpServletResponse res) throws ServletException,IOException {
JspFactory factory = JspFactory.getDefaultFactory();
if(factory==null) {
log.error("im getting this error all the time.....");
}
StringResponse tempResponse = new StringResponse();
PageContext pageContext = factory.getPageContext( this, //the requesting servlet
req, //the current request pending on the servlet
tempResponse, //the current response pending on the servlet
null, //the URL of the error page for the requesting JSP, or null
false, //true if the JSP participates in a session
1024, //size of buffer in bytes, PageContext.NO_BUFFER if no buffer, PageContext.DEFAULT_BUFFER if implementation default.
true //should the buffer autoflush to the output stream on buffer overflow, or throw an IOException?
);
pageContext.include(req.getRequestURI());
String parsedJsp = tempResponse.getString();
// now i can use the parsedJsp for generation of
// somekinda file... let's say a pdf from a tex doc in which i
// i used jsp....
}
Please could somebody help me with this, since i dont get it to work myselve and im now working on it for a to long time :)
--
Eduard Witteveen Systeemontwikkelaar NOS Internet
Mediacentrum Kamer 203, tel. +31(0)35 6773059
Sed quis custodiet ipsos custodes? : The sixth Satire from Juvenal