This week's book giveaway is in the OCPJP forum. We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line! See this thread for details.
Hi, I am running Java Web Server 2.0 Please go through my code. (its not long....) The problem is that the HTML output does not take in to account GMT, once EST is defined for the param name. This program takes the param value and sets the time zone so that, current time in that time zone is returned. The output looks like this The current time here is: XXXXXX //takes default time And the time in New York is: EST XXXXX //time for EST And the time in London is EST XXXXXXX The third line should actually read EST instead of GMT. But in the shtml file its GMT. This is my .shtml file that I wrote
The current time here is: And the time in New York is:
And the current time in London is: And the CurrentTime class looks like :-
[This message has been edited by Frank Carver (edited October 04, 1999).]
Well, I don't have a solution (yet), but I do have a few questions and a couple of minor code suggestions. I hope you don't mind, but I also tidied up your post so the html in your shtml example is actually visible (ut had been eaten by UBB), and your Java is a little more readable. First, have you tested the servlet independent of the shtml to see if it works. Try entering <pre> http://whatever../CurrentTime?zone=GMT </pre> and then <pre> http://whatever../servlets/CurrentTime?zone=EST </pre> to see if you get different results. This should isolate whether the problem is in your servlet code. If this test works, then the problem is either in the shtml or in the servlet engine. Can you tell us which server and/or servlet engine you are using? Second, a few small code suggestions: 1. Recent versions of the servlet API (2.0 and up, I think) have a method ServletResponse.getWriter() which returns a PrintWriter direct, so there's no need to build one from a Stream if you are using such a system. 2. A 'try' with no 'catch' or 'finally' is wasted space. The try and its braces may be safely removed.
Thanks for your suggestions. I had no idea that the html file I included will not be readable. Earlier, I did get the printWriter from getWriter() method, but the O Reilly Book (Java Servlet Programming ) suggested that there Java Web Server 1.1.1( But I thought that the same problem exists with Jwb 2.0 and wanted to elimnate all chances of error ) Anyways, I tried all the methods you suggested. The program worked for all cases The servlet engine I use is Java Web Server 2.0 Someone suggested that I go to the server applet and change the setting under the Servlet tab and load servlets at startup and "Now", the problem should go away. But, unfortunaltely it does not. Thanks in advance....
Joined: Jan 07, 1999
Given that your Java code works, my top guess would be that your shtml processor is cacheing requests to servlets. If the shtml processor also handles "ordinary" shtml syntax, try invoking the servlet output as a server-side-include using syntax like
This should invoke the servlet separately each time. Please let me know if this works.
Joined: Feb 10, 1999
Hi, Sorry for the delay, I tried to invoke the servlet using SSI. It did not work. I hope this syntax is correct <!--#include File = "pathandclassname"--> The error I got :- [an error occurred while processing server side includes] I am wondering whether I have to configure the Java Web Server for it to run SSI. There are some sample SSI's (eg dateservlet which prints local date and time) Its added as part of the Servlet Tab. I wrote a shtml to use it and this worked fine, although it was not loaded at server startup. I am pretty perplexed about this. Why is the server not considering the second <PARAM> in the .shtml code ? Thanks for all your suggestions.
Joined: Jan 07, 1999
I think that the reason your original setup wasn't working was that your shtml processor is either (a) not passing the parameters correctly to your servlet, or (b) invoking the servlet only once, and reusing the generated value each time the servlet tag appears. To test for (a), try setting <b>all</b> the PARAMs to some other timezone entirely, and checking that they all show the new timezone. If they still show the old values, even when you fully reload the page, then there is a problem with passing parameters. If they show the new values, then the problem is elsewhere. To test for (b), try reordering the servlet tags so that the timezones should appear in a different order. If the output changes, but all the values are still the same as each other, then you know that only one of the servlet calls is actually working. In either case, you really need to try and find the servlet output log, and start logging some diagnostics during processing of your servlet. If you find where System.out is being sent (depends on the webserver/servlet engine - I'm not familiar with JWS 2.0), then you can log the invocation times, parameter values, and generated date information for every call. This should help a lot. As for the attempt to invoke the servlet using ssi, you might want to try using "virtual=" instead of "file=" in the include directive. If supported, this should invoke a servlet or cgi program by URL rather than by file path and name. There should also be some log file information at the server end which will explain exactly what is going wrong; it might just be that you've inadvertently mistyped a name or something.