Cannot forward after response has been committed

2005-09-19 Thread Michael Lai
I have a jsp page that processes a login.  The (simplified) code is 
something like this:


%@ page language=java%
%
String userid = request.getParameter(userid);
String pw = request.getParameter(pw);

/* code to check user id and password */

if (user not found)
  pageContext.forward(login.jsp);
else
  pageContext.forward(userpage.jsp);
%

Please note that nowhere in my jsp code do I use the out object or 
send some outputs back to the client.  Yet, I am getting this Cannot 
forward after response has been committed error.  If I comment out the 
forward statements then the error disappears.  Any help is appreciated.


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Cannot forward after response has been committed

2005-09-19 Thread Michael Lai

I have an index.jsp page that checks a user's access level:

%@ page language=java errorPage= %
%
String userid = (String)session.getAttribute(UserId);

if (userid == null) {
  pageContext.forward(login.jsp);
} else {
  String access = (String)session.getAttribute(Access);

  switch (access.charAt(0)) {
 case 'A':
pageContext.forward(admin/index.jsp);
 case 'R': case 'W':
pageContext.forward(db/index.jsp);
 default:
pageContext.forward(login.jsp);
  }
}
%

And yet the above page works even with the %@ page language=java % 
line.  I don't understand why the above code works but the doesn't work 
for another page.


What do you propose -- that I remove the %@ page... % line?

[EMAIL PROTECTED] wrote:


Actually, the line end after the first line is sent back to the client,
with apropriate html headers invented.
%@ page language=java%%// now the line end is in java not in html

Yep, looks ugly.
What is even worse is code that sends a redirect and does NOT do a return.

-Original Message-
From: Michael Lai [mailto:[EMAIL PROTECTED]
Sent: Monday, September 19, 2005 10:17 PM
To: Tomcat Users List
Subject: Cannot forward after response has been committed


I have a jsp page that processes a login.  The (simplified) code is 
something like this:


%@ page language=java%
%
String userid = request.getParameter(userid);
String pw = request.getParameter(pw);

/* code to check user id and password */

if (user not found)
  pageContext.forward(login.jsp);
else
  pageContext.forward(userpage.jsp);
%

Please note that nowhere in my jsp code do I use the out object or 
send some outputs back to the client.  Yet, I am getting this Cannot 
forward after response has been committed error.  If I comment out the 
forward statements then the error disappears.  Any help is appreciated.




-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Cannot forward after response has been committed

2005-09-19 Thread Michael Lai
I put a 'return' statement after every 'forward' statement in all my jsp 
pages and now it seems to be working.  Thanks for your feedback.


Actually, my linebreak occurs in the % % tags.  I think my email 
client might have reformatted my output before sending.


[EMAIL PROTECTED] wrote:


You want the line breaks, either line-feed or carriage-return, line-feed
to occur within the java or jsp code, not within the html code.
Sometimes the html is buffered and ignored when something else puts out
headers or such.

Within HTML, line breaks do not matter much
Before HTML, any line break implies that HTML has started and you can get
default headers without doing anything.
Within JSP or Java, line breaks do not matter much.

Choice of uglies.
%@ page ...
%% code here

%@ page ... %%
code here

%@ page %
---there is here the line break of the above line---
% at this point the response has been committed by outputting the above
\r\n or whatever



-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Cannot connect to database using DataSource

2005-09-14 Thread Michael Lai
I have a MySQL database in which I created a database named, javatest, 
and I am using Tomcat 5.5.9.  I have unable to connect my database using 
Java's DataSource method.  Here is my ROOT.xml setup for my application 
context:


Context path= docBase=/home/tomcat/applications/
debug=0 reloadable=true 
   Resource name=jdbc/DBTest type=javax.sql.DataSource
 auth=Container /
   ResourceParams name=jdbc/DBTest
parameter
nameusername/name
valuejavauser/value
/parameter
parameter
namepassword/name
valuejavadude/value
/parameter
parameter
namedriverClassName/name
valuecom.mysql.jdbc.Driver/value
/parameter
parameter
nameurl/name

valuejdbc:mysql://localhost/javatest?autoReconnect=true/value

/parameter
   /ResourceParams
/Context

I created a simple servlet to test the database connection:

public class TestSQL extends HttpServlet {
   private Connection conn = null;

   public void doGet(HttpServletRequest request,
 HttpServletResponse response) throws IOException, 
ServletException {
  
   response.setContentType(text/html);

   PrintWriter out = response.getWriter();

   try {
   Context ctx = new InitialContext();
   Context appContext = (Context)ctx.lookup(java:comp/env);
   DataSource ds = (DataSource)appContext.lookup(jdbc/DBTest);
   conn = ds.getConnection();
   } catch (Exception e) {
   e.printStackTrace();
   }
  
   if (conn != null) {

   out.println(Connection successful);
   } else {
   out.println(Unsuccessful);
   }
}

It prints out Unsuccessful.  I also tried using the traditional 
DriverManager and that works.  Here is my web.xml in case it is needed 
for analysis:


?xml version=1.0 encoding=ISO-8859-1?
web-app version=2.4 uri=http://java.sun.com/xml/ns/j2ee; 
 resource-ref
 res-ref-namejdbc/DBTest/res-ref-name
 res-typejavax.sql.DataSource/res-type
 res-authContainer/res-auth
 /resource-ref

 servlet
   servlet-nameTestSQL/servlet-name
   servlet-classTestSQL/servlet-class
 /servlet
 servlet-mapping
   servlet-nameTestSQL/servlet-name
   url-pattern/servlet/TestSQL/url-pattern
 /servlet-mapping
/web-app

I would appreciate it very much if someone can have a look at this and 
tell me what I am doing wrong with the DataSource alternative.


Michael.

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: How to serve just JSP (was: Re: JSP on RHEL4 with Apache httpd RPM?

2005-09-14 Thread Michael Lai

Peter Flynn wrote:

If you have a tomcat webapp that serves jsp's such as 
http://localhost:8080/mywebapp, then you can map jsp requests to that 
webapp using JkMount /mywebapp/*.jsp
   



Ah...this exposes the gap in my understanding.
Where do I get a tomcat webapp that serves jsp's? 
This is what I need. I thought one was built into Tomcat -- in fact I

thought JSP serving was the original purpose of Tomcat.

If Tomcat doesn't have any such webapp, where do I get one?
I certainly can't write one, as I'm not a Java programmer.



I am limited in my knowledge of tomcat but from my understanding, tomcat 
can be ran either as a standalone server or behind a webserver.  In your 
case, it seems like you don't actually need a webserver in front so you 
should be able to connect to tomcat using the url:


http://localhost:8080/

Just make sure in your server.xml that you have this line:

Connector port=8080 /

or whatever port you want to connect to.  In fact, I don't think you 
even need mod_jk if you are using tomcat as a standalone.


Hope that helps.

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: How to serve just JSP (was: Re: JSP on RHEL4 with Apache httpd RPM?

2005-09-14 Thread Michael Lai

KEREM ERKAN wrote:


OK, start with downloading and installing a binary version of Tomcat for
your OS and also download the 1.2.10 version of mod_jk. I think we should
handle the rest off list not to bother the list anymore.



Just to give you another option if you like.  I don't even use mod_jd.  
I make use of Apache's reverse proxy feature.  In my httpd.conf, I add 
the following lines in my virtual host:


ProxyPass /app http://localhost:8081/
ProxyPassReverse /app http://localhost:8081/

Just make sure you have loaded the following modules:

LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_ftp_module modules/mod_proxy_ftp.so
LoadModule proxy_http_module modules/mod_proxy_http.so
LoadModule proxy_connect_module modules/mod_proxy_connect.so

What the above does is when Apache sees an url like:

http://www.myhost.com/app

It passes all traffic to tomcat which is listening to port 8081 (on the 
same machine).  The beauty of this is that you can put this in your 
ssl.conf too and Apache will handle all encrypted traffic and passes it 
on to tomcat.  The only advantage I see from mod_jk is if you are using 
it for load balancing too.



-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Where to put context.xml?

2005-09-13 Thread Michael Lai
This is probably an obvious question to most but I am new with tomcat 
5.5 so I am still trying to figure things out.  I want to create a web 
project with the document base in /home/tomcat/applications as opposed 
to the normal webapps folder.  This is what I have in my server.xml:


Server port=8005 shutdown=SHUTDOWN

 GlobalNamingResources
   !-- Used by Manager webapp --
   Resource name=UserDatabase auth=Container
 type=org.apache.catalina.UserDatabase
  description=User database that can be updated and saved
  factory=org.apache.catalina.users.MemoryUserDatabaseFactory
 pathname=conf/tomcat-users.xml /
 /GlobalNamingResources

 Service name=Catalina
   Connector port=8081 /

   Engine name=Catalina defaultHost=localhost
 !-- Realm className=org.apache.catalina.realm.UserDatabaseRealm
resourceName=UserDatabase / --
 Host name=localhost debug=0
   Context path= docBase=/home/tomcat/applications/
debug=0 reloadable=true /
 /Host
   /Engine
  
 /Service

/Server

It works when I point my browser to http://www.myhost.com:8081/ and it 
shows a customized welcome page from my index.jsp.  However, as I 
understand it, Context should now be in its own xml file.  I extracted 
the Context content and placed it in context.xml.  I placed 
context.xml in $CATALINA_HOME/conf/Catalina/localhost, restarted tomcat 
but now the browser shows nothing.  I also tried placing it in the conf/ 
folder but that doesn't work either.  Where does the file go?


Thanks for any help in advance.

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Where to put context.xml?

2005-09-13 Thread Michael Lai

Allistair Crossley wrote:


Nearly. Rename your file ROOT.xml and a path of /ROOT and you're away. The 
other alternative is create in your web application folder META-INF/context.xml

Allistair



Thank you for your prompt replay, Allistair.  I choosed the second 
option and created the META folder.  So I now have:


/home/tomcat/applications/META-INF/context.xml

And my context.xml shows:

Context path= docBase=/home/tomcat/applications/
debug=0 reloadable=true 
/Context

I restarted tomcat but with the same effect.  Is there some other 
configuration that I have to modify to inform tomcat that I have a 
project in this folder?


Michael.

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Where to put context.xml?

2005-09-13 Thread Michael Lai

Allistair Crossley wrote:


Hi,

The docBase is just the folder where your web applications are located. You 
need to have a folder in applications for your web application. For the empty 
path application this is /ROOT.

Thus

Context path=/ROOT docBase=/home/tomcat/applications/
debug=0 reloadable=true 
/Context

Means a folder at

/home/tomcat/applications/ROOT/META-INF/context.xml



Thanks, it works now.  I used your first method instead.

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Where to put context.xml?

2005-09-13 Thread Michael Lai

Caldarale, Charles R wrote:


To again quote from the Tomcat doc for the path attribute of the
Context element:

The value of this field must not be set except when statically defining
a Context in server.xml, as it will be infered [sic] from the filenames
used for either the .xml context file or the docBase.

Also note that placing Context tags is server.xml is strongly
discouraged.



OK, I took out /ROOT from the path field and it still works.  But the 
context file must still be named ROOT.xml.  The application fails to 
work with any other filename.


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: ajp13 dies unexpectately

2001-07-16 Thread Michael Lai

Just curious, what version of apache are you using?  I am trying to get 
tomcat 3.2 to work with apache 2.0 but I couldn't compile mod_jk.  It 
says something like it couldn't find http_global_conf.h.

Regards,
Michael.

maarten hartsuijker wrote:

we have been running tomcat 3.2.2 with apache, mod_jk and ajp13 support for 
about 3 weeks now. In those weeks it has died 2 times unexpectately and the 
only thing the mod_jk.og is showing me is a jk_ajp13_worker.c (586)]: Error 
connecting to the Tomcat process. 

With a netstat I can see that 8009 is not up anymore, so both times I have 
issued a shutdown and a start. That works but (ofcourse) I'd rather not have 
this problem at all.

Anyone had this before and, better yet, found a solution?

kind regards,

Maarten Hartsuijker


.






help with compiling mod_jk

2001-07-14 Thread Michael Lai

Hi.  I am trying to configure Apache(2.0.16) on my linux system (redhat 
7.1) with tomcat (3.2).  According to tomcat's documentation, I should 
try to compile my own mod_jk module by downloading the source for 
jakarta-tomcat.  I downloaded it and then I ran the command as per 
documentation:

apxs -o mod_jk.so -I../jk -I/usr/local/jdk/include  
-I/usr/local/jdk/include/linux -c *.c ../jk/*.c

I have adjusted the java path accordingly so that it reflects $JAVA_HOME 
on my system.  However when I ran this command, I get the following errors:

libtool --silent --mode=compile gcc -pthread 
-I/usr/local/apache2/include -I../jk -I/usr/local/java/include 
-I/usr/local/java/include/linux  -c mod_jk.c  touch mod_jk.slo
mod_jk.c:76:31: http_conf_globals.h: No such file or directory
apxs:Break: Command failed with rc=65536

It says that it can't find the http_conf_globals.h file but I couldn't 
find it on my system even after doing a search.

Please help.  Thanks,
Michael.