I have downloaded the example code. In the directory src/com/ora/jsp/servlets, there are a PBControllerServlet class and a PBDispatcherServlet class.
I want to implement your Action Object design and get confused as to what files I need to look at. Where do I find what files belong to what example? |
Answer: Sorry about the confusion. The PBControllerServlet class corresponds to examples 14-1 through 14-3. It contains the logic for all actions as private methods. The PBDispatcherServlet class, the Action interface, all XXXAction classes and the ActionUtils class correspond to the example described in “A More Modular Design Using Action Objects”. |
Monthly Archives: February 2001
How can I use Tomcat behind IIS?
How can I configure Tomcat 3.2 with my IIS server so I don’t have to use http://localhost:8080? |
Answer:The documents under Tomcat’s doc directory describe how you can configure Tomcat the way you want, but here’s a brief answer.If all you want is to avoid specifying the port number, you can just tell Tomcat to use port 80 instead of port 8080. You can change this in the conf/server.xml file:
<!-- Normal HTTP --> <Connector className="org.apache.tomcat.service.PoolTcpConnector"> <Parameter name="handler" value="org.apache.tomcat.service.http.HttpConnectionHandler"/> <Parameter name="port" value="80"/> </Connector> After you make this change and restart Tomcat, you can use a URL like http://localhost/ instead. Note that if you try this on a Unix/Linux system, you must start Tomcat as “root”, which may be a security risk. On Windows, however, you can use port 80 from any login account. The only reason for running Tomcat behind IIS that I can think of is if you need to serve both JSP pages and dynamic content based on other non-Java technologies (ASP, CGI, etc). You can read more about how to use Tomcat with IIS in doc/tomcat-iis-howto.html. |
How can I use a different JSP directory than webapps for Tomcat?
How can I put JSP files in a directory other than /webapps/ when I use the Tomcat 3.2 container? |
Answer: The documents under Tomcat’s doc directory describe how you can configure Tomcat the way you want, but here’s a brief answer.Edit the conf/server.xml file and add an element like this for top level directory you want to store the JSP files in: <Context path="/myapp" docBase="C:/websites/myapp" crossContext="false" debug="0" reloadable="true" > </Context> Note, however, that the directory you specify as docBase must contain the complete web application directory structure, i.e. the WEB-INF directories as well as the JSP pages (see Chapter 2, 4 and Appendix D in the book for more info). You need to restart Tomcat for this change to take effect. |
How can I access a session scope bean in a servlet?
I create a java bean in the session scope using <jsp:useBean> in a JSP page. I then need to access the information held by the bean in a servlet. How can I get hold of the bean in the servlet? |
Answer: The JSP session scope corresponds to the javax.servlet.http.HttpSession class in the Servlet API. The session scope objects are saved as attributes for the current instance of this class, so you can get them with code like this in a servlet: HttpSession session = request.getSession(); String foo = (String) session.getAttribute("foo"); For more information about how to share objects between JSP pages and servlets, see Chapter 14 in the book. |
When do I need to call clearBody()?
In another JSP book, they make the point of clearing the body content after using it, so the same instance can be reused for another tag handler.In JavaServer Pages (O’Reilly), you do not say anything about calling the clearBody() method. When do I really have to call this method? |
Answer: Typically, you do not need to call the clearBody() method, and it has nothing to do with the container’s ability to reuse the BodyContent instance.According to the JSP 1.1 spec, the container is supposed to get an instance of the BodyContent class for each BodyTag by calling PageContext.pushBody(). The spec says that this method must return a “new” instance, but the language will likely be relaxed in JSP 1.2 to allow a container to use pooled instances instead. Anyway, the BodyContent instance it returns must be empty, so there’s no need to clear it for reuse reasons. This is also clarified in the description of setBodyContent() in the JSP 1.2 Proposed Final Draft. A scenario when you do need to call clearBody() is in an iterating tag handler class, if you push the processed body content to the parent’s “out” in doAfterBody(), i.e. for each pass through the body. In the iteration example in my book (Chapter 16), it’s not needed since I let the evaluation of the body for each pass accumulate and process all of it after the last pass in the doEndTag() method. |