Go4Expert

Go4Expert (http://www.go4expert.com/)
-   JSP (http://www.go4expert.com/forums/jsp/)
-   -   Data Retrieval-Separated JSP and HTML files (How to?) (http://www.go4expert.com/forums/data-retrieval-separated-jsp-html-files-t28878/)

IamNew 16Aug2012 07:31

Data Retrieval-Separated JSP and HTML files (How to?)
 
Hi there,

I am currently developing a web application. I have created one file with .jsp extension which combining both JSP and HTML codes. But for some purposes, I need to separate them into .jps and .html file accordingly without affection their function. How I possibly do that?

Here is my codes: (Example.jsp)
Code:

<%@ page language = "java" contentType = "text/html; charset = ISO-8859-1"
        import = "java.lang.*, java.util.*, java.text.*, java.sql.*"
%>
<jsp:useBean id="utilObj" class="beanPackage.UtilBean" scope="page"/>
<jsp:useBean id="dbObj" class="beanPackage.DatabaseBean" scope="page"/>
<jsp:useBean id="formatObj" class="beanPackage.FormatBean" scope="page"/>
<%

// mobile app variables
String strLicNo        = request.getParameter("LicNo");

// variables to display data
Vector arrLicName  = new Vector();  // to store licensee name
Vector arrBussName = new Vector();  // to store business name
Vector arrLicNo = new Vector(); // to store license no
Vector arrAdd1 = new Vector();      // to store address 1
Vector arrAdd2 = new Vector();      // to store address 2
Vector arrAdd3 = new Vector();      // to store address 3
Vector arrPostcode = new Vector();  // to store postcode
Vector arrCityName = new Vector();  // to store city name
Vector arrStateName = new Vector();  // to store state name
Vector arrCountryName = new Vector();  // to store country name
Vector arrEffectDate = new Vector();  // to store effective date
Vector arrLicType  = new Vector();  // to store remarks



// database parameters
Connection ocon  = null;
Statement stmt  = null;
ResultSet rs    = null;
String strSQL    = "";

try {
  ocon = dbObj.getConnection();
  stmt = ocon.createStatement();
 
  strSQL = "SELECT T15_00010.LICENSEE_NAME, T15_00020.BUSINESS_NAME, T15_00030.LIC_NO, ";
  strSQL += "T15_00021.ADDRESS1, T15_00021.ADDRESS2, T15_00021.ADDRESS3, ";
  strSQL += "T15_00021.POSTCODE, T_UM_CITY.CITY_NAME, T_UM_STATE.STATE_NAME, T_UM_COUNTRY.COUNTRY_NAME, ";
  strSQL += "T15_00033.PRINCIPAL_LICENSE, T15_00034.EFFECTIVE_DATE, T15_00034.EXPIRY_DATE, T01_15050.DESCRIPTION ";
  strSQL += "FROM T15_00010, T15_00020, T15_00021, T15_00030, T15_00033, T15_00034, T01_15050, T_UM_CITY, T_UM_STATE, T_UM_COUNTRY ";
  strSQL += "WHERE T15_00020.T15_00010_OBJECTID = T15_00010.OBJECTID ";
  strSQL += "AND T15_00021.T15_00020_OBJECTID = T15_00020.OBJECTID ";
  strSQL += "AND T15_00030.T15_00020_OBJECTID = T15_00020.OBJECTID ";
  strSQL += "AND T15_00033.T15_00030_OBJECTID = T15_00030.OBJECTID ";
  strSQL += "AND T15_00033.T01_15050_OBJECTID = T01_15050.OBJECTID ";
  strSQL += "AND T15_00034.T15_00033_OBJECTID = T15_00033.OBJECTID ";
  strSQL += "AND T_UM_CITY.CITY_CODE = T15_00021.CITY ";
  strSQL += "AND T_UM_STATE.STATE_CODE = T15_00021.STATE ";
  strSQL += "AND T_UM_COUNTRY.COUNTRY_CODE = T15_00021.COUNTRY ";
  strSQL += "AND T15_00030.LIC_NO = '"+strLicNo+"' ";
  strSQL += "GROUP BY T01_15050.CODE ";
  System.out.println(strSQL);
  rs = stmt.executeQuery(strSQL);
   
    while (rs.next()){
      arrLicName.add(rs.getString("T15_00010.LICENSEE_NAME"));
      arrBussName.add(rs.getString("T15_00020.BUSINESS_NAME"));
      arrLicNo.add(rs.getString("T15_00030.LIC_NO"));
      arrAdd1.add(rs.getString("T15_00021.ADDRESS1"));
      arrAdd2.add(rs.getString("T15_00021.ADDRESS2"));
      arrAdd3.add(rs.getString("T15_00021.ADDRESS3"));
      arrPostcode.add(rs.getString("T15_00021.POSTCODE"));
      arrCityName.add(rs.getString("T_UM_CITY.CITY_NAME"));
      arrStateName.add(rs.getString("T_UM_STATE.STATE_NAME"));
      arrCountryName.add(rs.getString("T_UM_COUNTRY.COUNTRY_NAME"));
      arrEffectDate.add(formatObj.dateDisplayFormat(rs.getString("T15_00034.EFFECTIVE_DATE")));
      arrLicType.add(rs.getString("T01_15050.DESCRIPTION"));
    }
  }

catch (Exception e) {
  e.printStackTrace();
}
finally {       
  // close ResultSet and Statement
  try { if(rs != null) rs.close(); } catch (Exception e) { e.printStackTrace(); }
  try { if(stmt != null) stmt.close(); } catch (Exception e) { e.printStackTrace(); }
  try { if(ocon != null) ocon.close(); } catch (Exception e) { e.printStackTrace(); }
}

%>
<html>
  <head>
        <link rel="stylesheet" href="images/style.css" type="text/css" />
        <title>Licensing</title>
  </head>
<body>
 <%-- <tr>
    <div id="topbar">
      <div align="right" style="padding:12px;" class="smallwhitetext"><a href="../home.jsp">Home</a> | <a href="../Outstanding_Bill/outstanding_bill.jsp" title="Outstanding Bill">Outstanding Bill</a> | <a href="license_list.jsp" title="License List">License Listing</a></div>
                </div>
        </tr>--%>
  <tr>
    <table width="98%" border="0" cellspacing="1" cellpadding="1">
      <tr>
        <td width="150px">
          <div class="logotext" style="margin:30px"><span class="orangelogotext">Licensing</span></div>
        </td>
        <td>
          <div id="contenttext">
            <div class="bodytext" style="padding:12px;" align="justify">
              <%-- License No., Licensee Name and Business Name --%>
              <%--<table width="98%" border="0" cellspacing="1" cellpadding="1">
                <tr><td colspan="3" class="TableHeader">License Search</td></tr>
              <%-- <tr>
                  <td class="TableLabel" width="150px">License No.</td>
                  <td class="TableDetail1" width="500px">
                    <INPUT type="submit" value="Search">
                  </td>
                </tr>--%>
                <%--<tr>
                  <td class="TableLabel" width="150px">Licensee Name</td>
                  <td class="TableDetail1" width="500px">
                    <%=formObj.drawTextField("text", "strLicName", "", strTextLen, "", "0", "")%>
                  </td>
                </tr>
                <tr>
                  <td class="TableLabel" width="150px">Business Name</td>
                  <td class="TableDetail1" width="500px">
                    <%=formObj.drawTextField("text", "strBusinessName", "", strTextLen, "", "0", "")%>
                    <INPUT type="submit" value="Search">
                  </td>
                <tr>
              </table>--%>
              <%
        out.print("<table width=\"100%\" border=0 cellspacing=\"1\" cellpadding=\"1\">");
        out.print("<tr><td colspan=\"13\" class=\"TableHeader\"><strong>License List</strong></td></tr>");
        out.print("<tr><td class=\"TableLabel\">No.</td>");
        out.print("<td class=\"TableLabel\">Licensee Name</td>");
        out.print("<td class=\"TableLabel\">Business Name</td>");
        out.print("<td class=\"TableLabel\">License No</td>");
        out.print("<td class=\"TableLabel\">Address 1</td>");
        out.print("<td class=\"TableLabel\">Address 2</td>");
        out.print("<td class=\"TableLabel\">Address 3</td>");
        out.print("<td class=\"TableLabel\">Postcode</td>");
        out.print("<td class=\"TableLabel\">City Name</td>");
        out.print("<td class=\"TableLabel\">State Name</td>");
        out.print("<td class=\"TableLabel\">Country Name</td>");
        out.print("<td class=\"TableLabel\">License Type</td>");
        out.print("<td class=\"TableLabel\">Effective Date</td>");
        out.print("<td>&nbsp</td></tr>");
       
        int intTotKids = arrLicName.size();
                  int rowCount = 1;
                  String segTable;
                  String rowLabel = "";
                     
                  for (int intDraw=0; intDraw<intTotKids; intDraw++) {
                    if (intDraw%2==0)
                      rowLabel = "rowLabelEven";
                    else
                      rowLabel = "rowLabelOdd";
         
          segTable = "<tr>";
          segTable += "<td class=\""+rowLabel+"\">"+rowCount+"</td>";
          segTable += "<td class=\""+rowLabel+"\">"+arrLicName.get(intDraw)+"</td>";
          segTable += "<td class=\""+rowLabel+"\">"+arrBussName.get(intDraw)+"</td>";
          segTable += "<td class=\""+rowLabel+"\">"+arrLicNo.get(intDraw)+"</td>";
          segTable += "<td class=\""+rowLabel+"\">"+arrAdd1.get(intDraw)+"</td>";
          segTable += "<td class=\""+rowLabel+"\">"+arrAdd2.get(intDraw)+"</td>";
          segTable += "<td class=\""+rowLabel+"\">"+arrAdd3.get(intDraw)+"</td>";
          segTable += "<td class=\""+rowLabel+"\">"+arrPostcode.get(intDraw)+"</td>";
          segTable += "<td class=\""+rowLabel+"\">"+arrCityName.get(intDraw)+"</td>";
          segTable += "<td class=\""+rowLabel+"\">"+arrStateName.get(intDraw)+"</td>";
          segTable += "<td class=\""+rowLabel+"\">"+arrCountryName.get(intDraw)+"</td>";
          segTable += "<td class=\""+rowLabel+"\">"+arrLicType.get(intDraw)+"</td>";
          segTable += "<td class=\""+rowLabel+"\">"+arrEffectDate.get(intDraw)+"</td>";
          segTable += "</tr>";
          out.print(segTable);
          rowCount++;
        }
              %>
            </div>
          </div>
        </td>
      </tr>
    </table>
  </tr> 
</body>
</html>

I wish to separate the code into example.jsp which only does the processing and the .html only display the result. Please advise. Thanks in advance.


All times are GMT +5.5. The time now is 07:54.