> Ok, here the code for the servlet that generates HTML:

[snip]

I noticed that you have a quite common misconception about what servlets are. 
A servlet should generally not have any member variables, only local variables 
that are passed between methods. (I'm talking about pageHtml, selectedLang 
and selectedType in your example.) This is because servlets are instanciated 
ONCE by the servlet container and called on each request from separate threads. 
Your code has sharing violations in that if two (or more) request made at the 
same time, they will both enter doPost and use THE SAME pageHtml instance. 
The output could be a mixed caos of both threads output.

Even worse, the init method will only be called once when the servlet is instanciated,
so you never reset pageHtml. This will have the efect that all output is accumulated.
After 4 requests pageHtml will contain:

<HTML><HEAD>...</HEAD></HTML>
<HTML><HEAD>...</HEAD></HTML>
<HTML><HEAD>...</HEAD></HTML>



Probably this has something to do with your problem.

...johahn

> package simple_chart_view;
> 
> import java.io.*;
> import javax.servlet.*;
> import javax.servlet.http.*;
> import java.util.Enumeration;
> 
> /**
>  * <p>Title: </p>
>  * <p>Description: </p>
>  * <p>Copyright: Copyright (c) 2004</p>
>  * <p>Company: </p>
>  * @author not attributable
>  * @version 1.0
>  */
> 
> public class Servlet_SIMPLE_Chart_View
>  extends HttpServlet {
>  private static final String CONTENT_TYPE = "text/html";
>  //Initialize global variables
>  private StringBuffer pageHtml = new StringBuffer();
>  private String selectedLang = "";
>  private String selectedType = "";
> 
>  public void init() throws ServletException {
>     pageHtml = new StringBuffer();
>     selectedLang = "";
>     selectedType = "";
>  }
> 
>  //Process the HTTP Get request
>  public void doGet(HttpServletRequest request, HttpServletResponse response)
> throws
>   ServletException, IOException {
>   doPost(request, response);
>  }
> 
>  //Process the HTTP Post request
>  public void doPost(HttpServletRequest request, HttpServletResponse
> response) throws
>   ServletException, IOException {
> 
>     selectedLang = request.getParameter("lang");
>     selectedType = request.getParameter("type");
>   response.setContentType(CONTENT_TYPE);
>   constructPage();
>   PrintWriter out = response.getWriter();
>   out.println(pageHtml.toString());
>   out.flush();
>   out.close();
>  }
> 
>  //Clean up resources
>  public void destroy() {
>  }
> 
>  private void constructPage() {
>     java.util.Random rand = new java.util.Random();
>     int randInt = rand.nextInt();
>   pageHtml.append("<HTML>");
>   pageHtml.append("<HEAD>");
>   pageHtml.append("<TITLE>SIMPLE Chart</TITLE>");
>   pageHtml.append("</HEAD>");
>   pageHtml.append("<BODY>");
>   pageHtml.append("<P>");
>   pageHtml.append("Time Series Graph");
>   pageHtml.append("<P>");
>     if( selectedType != null ) {
>       if( selectedType.equalsIgnoreCase("0") ) {
>         pageHtml.append("<IMG SRC=\"ServletChartGenerator");
>       }
>       else if( selectedType.equalsIgnoreCase("1") ) {
>         pageHtml.append("<IMG SRC=\"ServletChartGenerator1");
>       }
>       else if( selectedType.equalsIgnoreCase("2") ) {
>         pageHtml.append("<IMG SRC=\"ServletChartGenerator2");
>       }
>     }
>     else{
>       pageHtml.append("<IMG SRC=\"ServletChartGenerator");
>     }
>     if( selectedLang != null ) {
>       if( selectedLang.equalsIgnoreCase("EN") ) {
>         pageHtml.append("?lang=EN&id=" + randInt + "\"");
>       }
>       else if( selectedLang.equalsIgnoreCase("FR") ) {
>         pageHtml.append("?lang=FR&id=" + randInt + "\"");
>       }
>       else if( selectedLang.equalsIgnoreCase("ALL") ) {
>         pageHtml.append("?lang=ALL&id=" + randInt + "\"");
>       }
>     }
>     else{
>       pageHtml.append("?lang=ALL&id=" + randInt + "\"");
>     }
>     pageHtml.append(" BORDER=1 WIDTH=800 HEIGHT=600/>");
>   pageHtml.append("</BODY>");
>   pageHtml.append("</HTML>");
>  }
> }
> 
> I hope that will help.
> 
> ___________________________________________________________________________
> To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
> of the message "signoff SERVLET-INTEREST".
> 
> Archives: http://archives.java.sun.com/archives/servlet-interest.html
> Resources: http://java.sun.com/products/servlet/external-resources.html
> LISTSERV Help: http://www.lsoft.com/manuals/user/user.html
>

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

Reply via email to