Re: Server side forward across different webapps?
Yes, you can do this. You have to get the ServletContext of the other web app. Use your current servletContext and call getContext() with the uripath of the other web app. Use the returned context to get a RequestDispatcher. Use the RequestDispatcher as you would normally. See the servlet api as needed. Stanley Yue wrote: Hi all: I have two webapps running in the same tomcat process. I want to have one webapps perform a server-side forward to a servlet in the second webapps? Is this possible? If not, what are some of the workarounds? Thanks, Stanley - To start a new topic, e-mail: users@tomcat.apache.org To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
jsp optimization for db driver load and connection
This isn't Tomcat specific but general to any jsp container and its jvm. I am working on a site where almost everything is done through the jsp page plus one main java class to store state data. The site's jsp page may do up to 7 queries on the database. On each query, the statements are these: Driver DriverDB = (Driver)Class.forName(db_DRIVER).newInstance(); Connection ConnDB = DriverManager.getConnection(db_STRING,db_USERNAME,db_PASSWORD); PreparedStatement StatementDB = ConnDB.prepareStatement(SELECT * from table); ResultSet resultDB = StatementDB.executeQuery(); My 2 questions are: Does the forName call to load the driver get optimized out? Clearly the driver need only load once. Does the getConnection reuse the same connection that was done in the previous call on the same jsp page? There are some performance problems and I'm wondering if I should try to clean the code up or if the jvm does it for me through optimization. It's running on Tomcat 5.5.20 and JVM 5.x. The client won't pay for any major redesign so I'm looking for something small that could make a big impact. Thanks for any insight. Coral - To start a new topic, e-mail: users@tomcat.apache.org To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: jsp optimization for db driver load and connection
Thanks to everyone for the replies. I had kinda been hoping the connection pooling was somehow automatic with the latest version of Tomcat. I'll pass along the information to the decision-makers About 15-20 jsps would need to be changed. There's another 30 jsps but they are not high use (admin area). This webapp doesn't even have a web.xml file! I'd call it Model .05 -- not even model 1. Ha, ha. The code was written by someone else about 3 years ago. It was their first and only JSP project. Thanks for the great help! Coral Miller, Steve wrote: Ugh. Model 1 architecture :-) Connection pooling is the way to go here, definitely. Setup Tomcat to do it for you automatically on startup. Then, just grab a connection from the pool when you need it. Some good documentation on setting up and configuring Tomcat to do that is at http://tomcat.apache.org/tomcat-5.5-doc/jndi-datasource-examples-howto.h tml In you JSP then, all you would have to write is (after importing java.sql.* and javax.naming.*): Context initContext = new InitialContext(); Context envContext = (Context)initContext.lookup(java:/comp/env); DataSource ds = (DataSource)envContext.lookup(jdbc/foo); Connection conn = ds.getConnection(); Statement stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); ResultSet rs = stmt.executeQuery(query1); //run iterator loop and display stuff ResultSet rs = stmt.executeQuery(query2); //run iterator loop and display stuff . . rs.close(); conn.close(); //returns connection to tomcat-managed pool...always a good practice to insert this!! The advantage to this of course is that several database connections are established when tomcat is started and then placed into a pool. All you do is grab one that existssaving a *considerable* amount of transaction time and thus speeding up your page loads. In addition, should the database parameters change such as URL, username, or password, then you only have to change it in one place..the server.xml file. This is also important if you move between dev/test/prod environments and have to point at different database instances. I don't know how many jsp pages you'll have to alter, but I would suggest looking at using a bean that does all of the stuff I wrote out above and returns an iterator or result set through a method. Then, do the bean stuff in the jsp code (sorry...running out of time here...lol). Again, I don't see any other way to improve performance within the scope/limitations you have defined. Steve Miller Grabbing A Tomcat By The Tail - To start a new topic, e-mail: users@tomcat.apache.org To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To start a new topic, e-mail: users@tomcat.apache.org To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: tomcat inserts leading / on include file
I tried a few things and the only thing that worked was as below. Host name=www.myhostname.com debug=5 appBase=/home/perap/htdocs/perap unpackWARs=true autoDeploy=true xmlValidation=false xmlNamespaceAware=false Context path= docBase=/home/perap/htdocs/perap/ROOT debug=5 privileged=true/ /Host PLUS also changing the httpd.conf VirtualHost DocumentRoot to also point to /home/perap/htdocs/perap/ROOT. In my case, I had to keep the Context entry but a more normal webapp probably would not need it. Thanks for all the help. Wouldn't have gotten there without the response. Mark Thomas wrote: IT Desk wrote: Here's the host entry in the Tomcat server.xml file (Yes I know I should have a separate context xml file but this is the way things already were when I started on this project): Host name=www.myhostname.com debug=5 appBase=/home/perap/htdocs/perap unpackWARs=true autoDeploy=true xmlValidation=false xmlNamespaceAware=false Context path=/ docBase=/home/perap/htdocs/perap debug=5 privileged=true/ /Host And there is the problem. appBase must not be the same as docBase. This is the issue I referred to in my previous mail. To get the behaviour your want you need move the contents of /home/perap/htdocs/perap to /home/perap/htdocs/perap/ROOT and change the host in your server.xml to: Host name=www.myhostname.com debug=5 appBase=/home/perap/htdocs/perap unpackWARs=true autoDeploy=true xmlValidation=false xmlNamespaceAware=false Context path=/ docBase=/home/perap/htdocs/perap/ROOT debug=5 privileged=true/ /Host Mark - To start a new topic, e-mail: users@tomcat.apache.org To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To start a new topic, e-mail: users@tomcat.apache.org To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
tomcat inserts leading / on include file
In my jsp, I have: %@ include file=Connections/db.jsp % and get error: org.apache.jasper.JasperException: /index.jsp(2,0) File /Connections/db.jsp not found The error message is showing a leading / was inserted. Why is that? I'm using Tomcat version 5.5.20. I tried hardcoding the full path but that didn't help either. I also tried putting the / in front of Connections and that didn't work either. I also tried just putting the context in front of Connections. But that didn't work either. Any ideas of what I have not tried or what is causing the problem? Thanks in advance. - To start a new topic, e-mail: users@tomcat.apache.org To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: tomcat inserts leading / on include file
It runs fine under 5.5.7. It was when I upgraded to 5.5.20 that I got this error. The include would work fine if tomcat didn't do an insert of the leading forward slash to the path. Parsons Technical Services wrote: What OS? Case sensitivity? Spelling? \ instead of a / ? Just thoughts. Doug - Original Message - From: IT Desk [EMAIL PROTECTED] To: Tomcat Users List users@tomcat.apache.org Sent: Thursday, November 30, 2006 8:25 PM Subject: tomcat inserts leading / on include file In my jsp, I have: %@ include file=Connections/db.jsp % and get error: org.apache.jasper.JasperException: /index.jsp(2,0) File /Connections/db.jsp not found The error message is showing a leading / was inserted. Why is that? I'm using Tomcat version 5.5.20. I tried hardcoding the full path but that didn't help either. I also tried putting the / in front of Connections and that didn't work either. I also tried just putting the context in front of Connections. But that didn't work either. Any ideas of what I have not tried or what is causing the problem? Thanks in advance. - To start a new topic, e-mail: users@tomcat.apache.org To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To start a new topic, e-mail: users@tomcat.apache.org To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To start a new topic, e-mail: users@tomcat.apache.org To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: tomcat inserts leading / on include file
Here's the host entry in the Tomcat server.xml file (Yes I know I should have a separate context xml file but this is the way things already were when I started on this project): Host name=www.myhostname.com debug=5 appBase=/home/perap/htdocs/perap unpackWARs=true autoDeploy=true xmlValidation=false xmlNamespaceAware=false Context path=/ docBase=/home/perap/htdocs/perap debug=5 privileged=true/ /Host So the directory structure is: /home/perap/htdocs/perap /home/perap/htdocs/perap/Connection/db.jsp As you can see, the tomcat webapps directory is NOT being used. I also have a VirtualHost entry whose DocumentRoot points to: /home/perap/htdocs/perap Mark Thomas wrote: IT Desk wrote: It runs fine under 5.5.7. It was when I upgraded to 5.5.20 that I got this error. The include would work fine if tomcat didn't do an insert of the leading forward slash to the path. Can you provide your directory structure within your app? I am expecting to see something like: HostAppBase/Context/index.jsp HostAppBase/Context/Connection/db.jsp Just a wild guess but does your directory structure look like this? HostAppBase/index.jsp HostAppBase/Connection/db.jsp This layout is unsupported and only worked in earlier versions due to a bug which has since been fixed. If you want your app to be the root app your directory structure needs to be: HostAppBase/ROOT/index.jsp HostAppBase/ROOT/Connection/db.jsp HTH, Mark - To start a new topic, e-mail: users@tomcat.apache.org To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To start a new topic, e-mail: users@tomcat.apache.org To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: tomcat inserts leading / on include file
OK. I guess it was just a Tomcat bug that it ran under 5.5.7. I'll post the results of the test to let others know once I can schedule the server for the test. Mark Thomas wrote: IT Desk wrote: Here's the host entry in the Tomcat server.xml file (Yes I know I should have a separate context xml file but this is the way things already were when I started on this project): Host name=www.myhostname.com debug=5 appBase=/home/perap/htdocs/perap unpackWARs=true autoDeploy=true xmlValidation=false xmlNamespaceAware=false Context path=/ docBase=/home/perap/htdocs/perap debug=5 privileged=true/ /Host And there is the problem. appBase must not be the same as docBase. This is the issue I referred to in my previous mail. To get the behaviour your want you need move the contents of /home/perap/htdocs/perap to /home/perap/htdocs/perap/ROOT and change the host in your server.xml to: Host name=www.myhostname.com debug=5 appBase=/home/perap/htdocs/perap unpackWARs=true autoDeploy=true xmlValidation=false xmlNamespaceAware=false Context path=/ docBase=/home/perap/htdocs/perap/ROOT debug=5 privileged=true/ /Host Mark - To start a new topic, e-mail: users@tomcat.apache.org To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To start a new topic, e-mail: users@tomcat.apache.org To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]