1 Reply Latest reply: Feb 6, 2013 1:37 PM by Murray9654 RSS

    Left Navigation Page

    Tarak
      Hi Gurus,

      I am new to JSP so i need your help.

      I am Using Jdeveloper UDI to create JSP Pages.

      My main idea in creating JSP to display data from one or more tables.

      I created 2 pages called Serverpage.jsp and Messagecount.jsp and it is working fine as expected,

      Now i want to create home page and it should also have left navigation menu and it should contain MessageCount and MessageStatus.

      When i click on Messagecount or MessageStatus my home page should refresh and have to display new JSP page (MessageCount.jsp or Serverpage.jsp)

      I don't have any clue how to do it. Could some one please help me.

      Here is my JSP pages

      Serverpage.jsp
      <%@ page contentType="text/html;charset=windows-1252" isELIgnored="true"%>
      <!--<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>-->
      <html>
       <head>
        <title>Welcome to Monitoring Page!</title>
        <link type="text/css" rel="stylesheet" href="jdeveloper.css"/>
        <script language="javascript" type="text/javascript" src="Calender.js">
      
        </script>
        <script language="javascript" type="text/javascript"
                src="jquery-1.8.2.min.js">
       
        </script>
        <script language="javascript" type="text/javascript" src="loading.js">
       
        </script>
       </head>
       <body bgcolor="#a9c6c9">
        <h1 align="center">SOA Monitor</h1>
         
        <br>
         <form action="Serverpage.jsp">
         InterfaceName 
        <select name="query">
         <option value="nodata">Select</option>
         <option value="TSStoRMS">TSStoRMS</option>
         <option value="RMStoWMS">RMStoWMS</option>
         <option value="WMStoRMS">WMStoRMS</option>
        </select>
         Name 
        <select id="second" name="itemww">
         <option value="nodata">Select</option>
        </select>
         Id 
        <input type="text" name="queryrow"/>
         FromDate 
        <input id='fromdate' type="text" size="20"></input>
         
        <a href="#" onclick="NewCal('fromdate','ddmmmyyyy')"> 
         <img src="cal.gif" width="16" height="16" border="0" alt="Pick a date"></img></a>
         ToDate 
        <input id='todate' type="text" size="20"></input>
         
        <a href="#" onclick="NewCal('todate','ddmmmyyyy')"> 
         <img src="cal.gif" width="16" height="16" border="0" alt="Pick a date"></img></a>
         
        <input type="button" value="Go"/>
        
        <a href="MesssageCount.jsp">Goto MessageCount</a>
        
        </form>
         
           
        <br>
        
        <br>
        
        <table cellspacing="2" cellpadding="3" border="1" width="100%">
         <thead>
          <tr bgcolor="#f7f6f9">
           <th width="15%" align="center"> Title</th>
           <th width="15%" align="center"> Status</th>
           <th width="15%" align="center"> Completion Date</th>
          </tr>
         </thead>
          
         <tbody></tbody>
        </table>
       </body>
      </html>
      MessageCount.jsp
      <%@ page contentType="text/html;charset=windows-1252"
               import="java.io.*,java.util.*,java.sql.*,java.sql.ResultSet,java.sql.Connection"
               isELIgnored="true"%>
      <!--<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>-->
      
      <html>
        <head>
        <title>Welcome to Monitoring Page!</title>
        <link type="text/css" rel="stylesheet" href="jdeveloper.css"/>
        <script language="javascript" type="text/javascript" src="Calender.js">
       
        </script>
        <script language="javascript" type="text/javascript"
                src="jquery-1.8.2.min.js">
       
        </script>
        <script language="javascript" type="text/javascript" src="LoadMessageCount.js">
      
        </script>
        
       </head>
      <body bgcolor="#a9c6c9">
        <h1 align="center">Message Count</h1>
         
        <br>
         
        <br>
         
        <form action="MessageCount.jsp">
         InterfaceName
         <select name="query">
          <option value="nodata">Select</option>
          <option value="TSStoRMS">TSStoRMS</option>
          <option value="RMStoWMS">RMStoWMS</option>
          <option value="WMStoRMS">WMStoRMS</option>
         </select>
         Name
         <select id="second" name="itemww">
         <option value="nodata">Select</option>
         </select>
         FromDate
         <input id='fromdate' type="text" size="20"></input>
         <a href="#" onclick="NewCal('fromdate','ddmmmyyyy')"> 
          <img src="cal.gif" width="16" height="16" border="0" alt="Pick a date"></img></a>
         ToDate
         <input id='todate' type="text" size="20"></input>
         <a href="#" onclick="NewCal('todate','ddmmmyyyy')"> 
          <img src="cal.gif" width="16" height="16" border="0" alt="Pick a date"></img></a>
         <input type="button" value="Go"/>
        </form>
         
        <br>
        <table cellspacing="2" cellpadding="3" border="1" width="100%">
         <thead>
          <tr bgcolor="#f7f6f9">
           <th width="15%" align="center"> Total Messages</th>
           <th width="25%" align="center"> Sucess Messages</th>
           <th width="15%" align="center"> Failure Messages</th>
          </tr>
         </thead>
       <tbody></tbody>
        </table>
       </body>
      </html>
      Java code for ServerPage.jsp
      import java.io.IOException;
      import java.io.PrintWriter;
      import DB.DataHandler;
      import java.sql.Date;
      import java.sql.ResultSet;
      import java.sql.SQLException;
      
      import javax.servlet.*;
      import javax.servlet.http.*;
      public class example extends HttpServlet {
          private static final String CONTENT_TYPE =
              "text/html; charset=windows-1252";
      
          public void init(ServletConfig config) throws ServletException {
              super.init(config);
          }
      
          public void doGet(HttpServletRequest request,
                            HttpServletResponse response) throws ServletException,
                                                                 IOException {
              response.setContentType(CONTENT_TYPE);
              PrintWriter out = response.getWriter();
              String result;
              ResultSet rs;
              rs = null;
               int rowcount=0;
              try {
                  DataHandler datahandler = new DataHandler();
      
                  String r = null;
                  String interfaceName = request.getParameter("interfaceNam");
                  
                  
                  String n = request.getParameter("name");
                  r = request.getParameter("row");
                  String td = request.getParameter("todate");
                  String fd = request.getParameter("fdate");
                  
                 
                  if (!(r.equalsIgnoreCase("nodata"))) {
      
                      rs = datahandler.getInstancesByInstanceId(r,n,interfaceName);
                  }
      
                  else if (!(n.equalsIgnoreCase("nodata"))) {
      
                      rs = datahandler.getAllInstancesByCompositeName(n);
                  } else if (!(td.equalsIgnoreCase("nodata")) && !(fd.equalsIgnoreCase("nodata")) )
                      
                  {
                      rs = datahandler.getInstancesByDate(td,fd);  
                  }
                  while (rs.next()) {
                    if(rowcount% 2==0 )
                    {                  
                      out.println("<tr bgcolor=\"#fff0fe\">");
                      out.print("<td align=\"center\" >" + rs.getString(1) +
                                "</td>");
                      
                      if (rs.getInt(2) == 8)
                          result = "Terminated";
                      else if (rs.getInt(2) == 5)
                          result = "completed";
                      else
                          result = "Errored";
                      out.print("<td align=\"center\">" + result + "</td>");
                          out.print("<td align=\"center\">" + rs.getString(3) + "</td>");
                      out.println("</tr>");
                    }
                    else{               
                        out.println("<tr bgcolor=\"#ffd6d6\">");
                      out.print("<td align=\"center\" >" + rs.getString(1) +
                                "</td>");
                      
                      if (rs.getInt(2) == 8)
                          result = "Terminated";
                      else if (rs.getInt(2) == 5)
                          result = "completed";
                      else
                          result = "Errored";
                      out.print("<td align=\"center\">" + result + "</td>");
                          out.print("<td align=\"center\">" + rs.getString(3) + "</td>");
                      out.println("</tr>");
                        }
                      rowcount=rowcount+1;
                      }
                   
                  
      
              } catch (Exception e) {
                  out.println("<tr bgcolor=\"#a5c6ff\">");
                  out.print("<td align=\"center\" >" + "No Data Found" + e +
                            "</td></tr>");
              }
      
              out.close();
          }
      }
      Java code for Messagecount.jsp
      import DB.MessageCount;
      import java.io.IOException;
      import java.io.PrintWriter;
      import java.sql.ResultSet;
      import java.sql.SQLException;
      import javax.servlet.*;
      import javax.servlet.http.*;
      
      
      public class MessageCnt extends HttpServlet {
          private static final String CONTENT_TYPE = "text/html; charset=windows-1252";
      
          public void init(ServletConfig config) throws ServletException {
              super.init(config);
          }
      
          public void doGet(HttpServletRequest request,
                            HttpServletResponse response) throws ServletException,
                                                                 IOException {
              response.setContentType(CONTENT_TYPE);
              PrintWriter out = response.getWriter();
              ResultSet rs;
              rs = null;
              
          try {
              MessageCount MsgCnt = new MessageCount();
      
             
              String n = request.getParameter("name");
            
              String td = request.getParameter("todate");
              String fd = request.getParameter("fdate");
          if (!(n.equalsIgnoreCase("nodata"))) {
      
              rs = MsgCnt.getMessageCountByCmpstName(n,fd,td);
          }
          while (rs.next()) {
           
                             
              out.println("<tr bgcolor=\"#fff0fe\">");
              out.print("<td align=\"center\" >" + rs.getString(1) +
                        "</td>");
              out.print("<td align=\"center\">" + rs.getString(2) + "</td>");
             
              out.print("<td align=\"center\">" + rs.getString(3) + "</td>");
              out.println("</tr>");
               
          } }catch (Exception e) {
              out.println("<tr bgcolor=\"#a5c6ff\">");
              out.print("<td align=\"center\" >" + "No Data Found" + e +
                        "</td></tr>");
          }
      
          out.close();
          }
                                                                 }
      Thanks in Advance

      Edited by: Tarak on Dec 14, 2012 11:29 AM
        • 1. Re: Left Navigation Page
          Murray9654
          you have posted so much for a simple solution. IDE does not matter at all. So coming to your problem, I mean if you are working just with servlets and jsp. write a servlet for your homepage which uses jdbc (java api to connect to database) to retrieve data from the database and store the data in the request using attributes and then the servlet should forward your request to the homepage jsp. In homepage jsp you will take the data from the request using jsp tags and jstl and will display it on home page jsp and finally rendered html will be sent to the browser where it displays your home page. on the home page jsp store the message count in a div and when you click on the div use javascript to submit the form which places a request to new jsp (may be message count jsp) which will be loaded into the browser.