Win a copy of Event Streams in Action this week in the Java in General forum!

Gert Cuppens

Ranch Hand
+ Follow
since Jul 13, 2003
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Gert Cuppens

I had the same problem during the last 3 weeks. And since I can only program in Java after my working hours, a week only means about 18 hours to look for the solution. I have searched several forums for the solution but thanks to Joeri Leemans, a Java pro, I looked at this thread.
And changing localhost into 127.0.0.1 was also for me the great breakthrough.
Thanks, guys !
To prevent caching, you should add the following code before the <HTML> tag of your JSP.


When you call a servlet, it might be necessary to add a date/time as parameter, like I had to do in the following part of my JSP.



The idea behind this is also to prevent caching. The proxy server at work was so lazy it always showed the first movie poster over and over again. With the date as parameter I prevented caching.
14 years ago
JSP
Whenever I see a "file not found" error, I know I have to look for 2 things.
1) Is the path correct ? Sometimes, adding a slash (/) can do the trick.
2) Is the called servlet or JSP defined in the web.xml. If it is not, then there is no way for the web server to know where it should look.
14 years ago
JSP

Originally posted by Giovanni De Stefano:

From Head First Servlet & JSP, page 54: the model is the only part of the system that talks to the database...

/QUOTE]

Mmmm, well, here I do not agree. I've seen web applications where the JSP takes care of the database connection, the servlet, or the DAO or Data Access Object. But never the model, as I see it. The model is just the collection of javabeans which reflects the concepts known to the user like Client, Product, Order, Orderline and so on.
In my opinion, the best way to follow the MVC model 2 is to provide DAO's or Data Acces Objects which connect to the database and execute the SQL statements.

14 years ago
My favourite book is the "Apache Tomcat Bible" from Eaves, Jones and Godfrey. It explains how to download and install Java, MySQL, Tomcat, Eclipse, Ant ... and above all, it gives an overview of the Model-View-Controller design pattern.
14 years ago
I'll give you as an example my own web.xml.
This web.xml tells Tomcat how to work with my web application
called gco. So, in my Tomcat folder, I have a folder C:\Program Files\Apache Software Foundation\Tomcat 5.0\webapps\gco.

Inside the WEB-INF folder of this web application "gco" is the web.xml and it contains the following code

<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">

<web-app>
<display-name>CLUIF</display-name>
<description>CLUb op het Internet voor Filmfanaten</description>
<servlet>
<servlet-name>LoggerServlet</servlet-name>
<servlet-class>org.gertcuppens.controller.LoggerServlet</servlet-class>
<init-param>
<param-name>properties</param-name>
<param-value>WEB-INF\classes\log4j.properties</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>

<servlet>
<servlet-name>org.gertcuppens.controller.CluifController</servlet-name>
<servlet-class>org.gertcuppens.controller.CluifController</servlet-class>
</servlet>
<servlet>
<servlet-name>org.gertcuppens.controller.ImageServlet</servlet-name>
<servlet-class>org.gertcuppens.controller.ImageServlet</servlet-class>
</servlet>


<servlet-mapping>
<servlet-name>org.gertcuppens.controller.CluifController</servlet-name>
<url-pattern>/cluif</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>org.gertcuppens.controller.ImageServlet</servlet-name>
<url-pattern>/cluifimg</url-pattern>
</servlet-mapping>



</web-app>

The most important servlet is CluifController.
With the following lines I tell Tomcat to which class belongs this Cluifcontroller. In my case, I've been too lazy to give a different name; so Class and name are the same.

<servlet>
<servlet-name>org.gertcuppens.controller.CluifController</servlet-name>
<servlet-class>org.gertcuppens.controller.CluifController</servlet-class>
</servlet>

And which URL should be used to invoke this servlet ?
<servlet-mapping>
<servlet-name>org.gertcuppens.controller.CluifController</servlet-name>
<url-pattern>/cluif</url-pattern>
</servlet-mapping>


So, when I start Tomcat on my PC with http://localhost:8080, I get
the default start screen of Tomcat. To invoke my web application I have to write http://localhost:8080/gco/cluif.

With /gco, Tomcat knows it has to look for the web.xml inside the gco-folder. And with /cluif, Tomcat knows it has to start the servlet called org.gertcuppens.controller.CluifController.
14 years ago
If you want to connect to a MySQL database, you could make an abstract class which contains the exact connection statement, referring to the class driver you are using. If you are to change this driver, there's only one place where you have to change the source code.

Here's the abstract class.

Another free book can be found at www.coreservlets.com.
The first edition of the book by Marty Hall "core servlets and Java Server Pages" is availabble in PDF format.
14 years ago
JSP
You should go to www.coreservlets.com. There, you can download for free the first edition of the book "core servlets and Java Server Pages" from Marty Hall.
Another very good book is the "Apache Tomcat Bible" from Eaves, Jones and Godfrey. The title is somehow misleading as it explains everything you need to start developing java web applications. It explains how to download Java, MySQL, Ant, Eclipse, Tomcat and how to test you've installed these downloads well.
And as a bonus, you get the source code of a web application which is developed following the principles of the Model-View-Controller (MVC) design pattern.
14 years ago
JSP
Kira, I advise you to start a new topic if you won't get an answer to your question soon. It is my experience that people think that the topic is solved as soon as it gets a number of replies.

So, don't wait too long. If you haven't got a good answer to your problem, start a new topic.
14 years ago
JSP
Kristian, you were right. It is the caching that showed me the first poster
all over again. I changed the line of code into this :


and with adding a superfluous parameter, I forced the proxyserver to show
me every poster I asked for. I tested it today at work and this did the trick. Thanks again.
14 years ago
JSP
You should take a look at http://www.coreservlets.com/.
THere you can download the first edition in pdf format of the famous book "core servlets and java server pages" from Marty Hall.

And a very good book for beginners is the "Apache Tomcat Bible" from Eaves, Jones and Godfrey. This book explains how to download and install Java, Tomcat, MySQL, Ant, Eclipse and other stuff you might need to build a web application. But the most important thing is that it gives you an overview of a web application built following the design principles of the Model-View-Controller. A must have, if I may say so.
14 years ago
JSP
Frankly, after reading your answer, I think it must be a cache problem. I already had this before at work with another web application. Then, the JSP's never changed. To solve this, I had to add the following lines to each JSP :

<%
response.setHeader("Cache-Control","no-cache");
response.setHeader("Expires", "0");
response.setHeader("Pragma", "No-cache");
response.addHeader("Cache-control", "no-store"); // tell proxy not to cache
response.addHeader("Cache-control", "max-age=0"); // stale right away
%>

But now it's different. The JSP's are all right, but the image shown is made by a servlet which is called inside a JSP with the following code

<td width="200" rowspan="6"><div align="center"><img src="/gco/cluifimg" width="150" height="200"></div></td>


the /gco/cluifimg is referred to a servlet which takes care of the translation from the blob into an array of bytes. This works fine at home, but at work, I suppose the proxyserver is only calling this servlet once, putting it into the cache, and never bother again to see if it has changed. So, I have to look for a way to prevent the caching of the output of this servlet.
14 years ago
JSP
I've made a small web application about movies. For those interested
to see it work : go to http://www.gertcuppens.org/servlet/cluif.
The web app works with servlets and JSP's.

Now the problem is this : in the local version, I can select on the first
page the letter "B" to get all movies starting with a B. When I select
, say, "Bad Santa" in thsi list, I can see the detail screen containing
the poster of the movie (a BLOB).
If I go back to the list and select "the Blob" from 1958, I see the poster
with the photo of Steve Mc QUeen. If I go back to the list once more,
I can select "the Blob" from 1988, and I see the poster from this movie.

So locally, everything is OK. Then I published the web application on my
web site, and this still keeps on working.
But when I go to the office, and try to go to my web application at work,
whichever poster I see first, this is the poster that will be shown on all
the other detail screens.
So, for instance, with the above scenarion, I see the data from "bad santa"
and its poster. If I go to the blob, I see the data of the blob (title, year)
but still the poster of "bad santa".

So, at work, I can only view the first poster, even though I select other
movies. Can anyone tell me where the error is ?
14 years ago
JSP
I've been with http://www.javaservlethosting.com/ for more than 2 years now. Take a look at their prices and decide if you're willing to pay for it.
If you want some free services, you should check out www.myjavaserver.com. This was previously www.mycgi.com but since they lacked the money to keep their server up, they got help from www.javalobby.org.
14 years ago
JSP