HI, sanjeev,

Thanks a lot for your help. Last time i send you my code which may not reach you. I add those code here .

Thanks in advance .

bin

/***********************************************************************************/

StatApplet.java, this is applet  program loaded in StatApplet.html. there is JeditorPane which associate

with servlet program (Section1servlet.java)inside/

/*************************************************************************************/

 
public class StatApplet extends JApplet implements ActionListener
{
  public void init()
  { 
    StatPanel = new JPanel();
    StatPanel.setLayout(new BorderLayout()); 
    JTabbedPane tabs = new JTabbedPane(SwingConstants.TOP)
    JPanel contentPanel = new JPanel();
    contentPanel.setLayout(new BorderLayout());

JPanel textPanel = new JPanel();
    textPanel.setLayout(new BorderLayout()); 
      sumPane = new JEditorPane();
  sumPane.setEditable(false);
    sumStr = "summary";
    initSum(sumStr, sumPane);
 
    JScrollPane scrollPane = new JScrollPane(sumPane);
    textPanel.add(scrollPane, "Center");

    contentPanel.add(textPanel, "Center");
    JPanel imagePanel = new JPanel();

    img = getImage(getCodeBase(), "money.gif");
    Icon icon = new ImageIcon(img);
    JButton button = new JButton(icon);

    imagePanel.add(button, "Center");
    contentPanel.add(imagePanel, "West");JPanel contentPanel4 = new JPanel();
    contentPanel4.setLayout(new BorderLayout());    JPanel subPanel3 = new JPanel();
    subPanel3.setLayout(new BorderLayout());

// this is JeditorPane which invoke servlet
   
try{
    sumPane3 = new JEditorPane(new URL("http://UrL/root/servlet/Section1Servlet"));
    }catch(IOException ex){
    }
    sumPane3.setEditable(false)

JScrollPane scrollPane3 = new JScrollPane(sumPane3);
    subPanel3.add(scrollPane3, "Center");

    JPanel controlPanel4 = new JPanel();
    controlPanel4.setLayout(new GridLayout(2, 1));Icon icon3 = new ImageIcon(img3);
    JButton button3 = new JButton(icon3);

    controlPanel4.add(button3, "Center");
    JPanel buttonPanel4 = new JPanel();
    buttonPanel4.setLayout(new GridLayout(2, 1));
    addButton(buttonPanel4, "Coin Flip Simulation");
    addButton(buttonPanel4, "Independent Dice Simulation");
    controlPanel4.add(buttonPanel4, "South");
  
    contentPanel4.add(subPanel3, "Center");
    contentPanel4.add(controlPanel4, "West");
tabs.addTab("Home", contentPanel);    tabs.addTab("Section 1", contentPanel4);
    tabs.addTab("Section 2", contentPanel3);
    tabs.addTab("Section 3", contentPanel2);  
    StatPanel.add(tabs,"Center");
   
    // add menu bar into stat applet panel   
    JMenuBar mbar= new JMenuBar();
    JMenu helpMenu= new JMenu("Help");
    helpMenu.setMnemonic('H');
    helpMenu.add(item= new JMenuItem("Contents", 'C'));
    item.addActionListener(this);
    mbar.add(helpMenu);
 
    StatPanel.add(mbar, "North");

    Container contentPane = getContentPane();
    contentPane.add(StatPanel);
  }


  
  }

 /************************************************************************************************************/

Section1Servlet.java. It is invoked from StatApplet.java. and it will invoke Showsection1.java via Response.sendredirect(). ShowSection1 always is invoked two times and when ShowSection1.java invoke another servlet program, the session attributes are lost.

/****************************************************************************************************/

/**
 * This application is invoked from StatApplet.java(Applet). It retrieves the questions
 * of section1 from database and put these questions in session.then invoke showSection1.java
 */
public class Section1Servlet extends HttpServlet {
        public synchronized void init (ServletConfig config) throws ServletException {
 try {
     super.init();
 } catch(Exception ex) {
 }
 
    }
    public void doGet (HttpServletRequest request,HttpServletResponse res) throws IOException, ServletException {
 PrintWriter out = res.getWriter();
 int allQuestion=0;  // total question number
 res.setContentType("text/html");

 // get session
 HttpSession session = request.getSession(true);
 session.setMaxInactiveInterval(-1);
       
  try{
      conn=getConnected();
      state = conn.createStatement();
  }  catch(Exception ex) {
      out.println("<hr>" +ex.getMessage() + "<hr>");
      return;
  }

  String query="select question,answer from questionsets where cid='"+"stat221"+"'  and sectionid='"+"1'";
 
  try{
      state = conn.createStatement();
      rset=state.executeQuery(query);
    
      while (rset.next()){
   data="rset.getString(1);   answer=rset.getString(2);
   QuestionV.add(data);
   AnswerV.add(answer);
   allQuestion++;
      }
   }  catch(Exception ex) {
       out.println("<hr>" +ex.getMessage() + "<hr>");
   }


   try{
      conn.close();
  }catch (Exception ex) {
      out.println("<hr>" +ex.getMessage() + "<hr>");
  } 
 
   session.setAttribute("SECTION1QSET",QuestionV);
   session.setAttribute("SECTION1ANSW",AnswerV);
   session.setAttribute("SECTION1TOTAL",new Integer(allQuestion));

// ShowSection1.java is invoked here
   res.sendRedirect("/root/servlet/ShowSection1"+"?Section1Servlet");
   // postForm(out);
   System.out.println("end of Section1Servlet");
   return;
    }

     /**
     * Create connection to database.
     * @return a connection.
     */
    private Connection getConnected() throws Exception {
 
 Class.forName("org.gjt.mm.mysql.Driver").newInstance();
 return (DriverManager.getConnection(dbstring));
    }
 
 
    /*   public void doPost(HttpServletRequest request,HttpServletResponse res) throws IOException,ServletException {
 doGet(request, res);
 } */
   
}

 




Post your free ad now! Yahoo! Canada Personals

Reply via email to