Dennis’s Weblog

JSP-Introduce

Posted on: October 11, 2008

<%@ page language=”java” contentType=”text/html; charset=UTF-8″
        pageEncoding=”UTF-8″
        import=”java.util.*”
        import=”java.sql.*”you should download the connector to connect to mysql from jsp.
        import=”com.mango.apccas2008.*”
%>

Here we can know how to import java library to JSP

<%@ taglib uri=”http://displaytag.sf.net” prefix=”display” %>

It use some java Decorator, it’s a free library.     Display:table   library.

It can do sorting, exporting, and many other thing,  —-Decorator Design Pattern, just for decorate the data, for example, in database data, a date :1908.09.20, and this Decorator class can transform it to 1908年09月20日.

<%

Here we can know the most important part to

Connection con = null;
Statement stmt = null;
ResultSet rs;
String sql = “”;
List resultList = new ArrayList();

String reqType=”S”;
if (request.getParameter(“r”)!=null)
 reqType = request.getParameter(“r”);

use request.getParameter(“r”) to get the value send by Html form, as blow “green color”
String url=””;variables
if (reqType.equals(“S”))
 url = “<font color=’red’ size=’3′>Success</font>&nbsp;<a href=‘/report.jsp?r=P’>Pending</a>”;
else if (reqType.equals(“P”))
 url = “<a href=’/report.jsp?r=S’>Success</a>&nbsp;<font color=’red’ size=’3′>Pending</font>”;

 
try {
    Class.forName(“com.mysql.jdbc.Driver”).newInstance();create instance
    con = DriverManager.getConnection(“jdbc:mysql:///apccas2008″,”root”, “”);//use the driver connect to database mysql, and JSP programm just direct connect to Drive on local machine, this is much quicker than direct connect to mysql database (ODBC have the same sense)

    if(!con.isClosed()) {
          
  sql = “Select * from payment where paymentstatus='” + reqType + “‘ order by id desc”;
  
  stmt=con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);  
  
  rs = stmt.executeQuery(sql);
      
  while (rs.next()) {

   Payment payment = new Payment();
   payment.setAmount(rs.getString(“amount”));
   payment.setAmount_usd(rs.getString(“amount_usd”));
   payment.setCon_priceclass(rs.getString(“con_priceclass”));
   payment.setId(rs.getString(“id”));
   payment.setMerch_ref(rs.getString(“merch_ref”));
   payment.setPaperid(rs.getString(“paperid”));
   payment.setPaymentmethod(rs.getString(“paymentmethod”));
   payment.setPaymentstatus(rs.getString(“paymentstatus”));
   payment.setPaymenttype(rs.getString(“paymenttype”));
   payment.setSerialno(rs.getString(“serialno”));
   payment.setTicket1(rs.getString(“ticket1”));
   payment.setTicket2(rs.getString(“ticket2”));
   payment.setTitle(rs.getString(“title”));
   payment.setTut_role(rs.getString(“tut_role”));
   payment.setTutorial(rs.getString(“tutorial”));
   payment.setTxn_date_time(rs.getString(“txn_date_time”));
   payment.setTxn_message(rs.getString(“txn_message”));
   payment.setUserid(rs.getString(“userid”));
   
   resultList.add(payment);
  }
  
  rs.close();
  stmt.close();
  con.close();
  
   }
  } catch(Exception e) {
    e.printStackTrace();
   System.out.println(e.getMessage());
  } finally {
    try {
      if(con != null)
        con.close();
    } catch(SQLException e) {
  e.printStackTrace();
  System.out.println(e.getMessage());
   }
  }
%>

<%
request.setAttribute( “paymentList”, resultList);
%>
<html>
<head>
 <title>APCCAS 2008 Report</title>
 <link href=”css/screen.css” rel=”stylesheet” type=”text/css” />
</head>
<body>

the library refer to previously
<display:table name=”paymentList” export=”true” class=”ISIS” pagesize=”20″ defaultsort=”1″ defaultorder=”descending” decorator=”com.mango.apccas2008.DataWrapper”>
   <display:caption>
    <strong>
     APCCAS 2008 Registration – <%=url %>     
    </strong>
   </display:caption>
 <display:column property=”id” title=”ID”/>
 <display:column property=”userid” title=”User id”/>
 <display:column property=”amount” title=”Amount(MOP)”/>
 <display:column property=”amount_usd” title=”Amount(USD)”/>
 <display:column property=”paymentmethod” title=”Payment Method”/>
 <display:column property=”paymentstatus” title=”Payment Status”/>
 <display:column property=”serialno” title=”Serial No”/>
 <display:column property=”txn_date_time” title=”Date”/>  
 <display:column property=”title” title=”Title”/>
 <display:column property=”con_priceclass” title=”Price Class”/>  
 <display:column property=”ticket1″ title=”Welcome Reception”/>
 <display:column property=”ticket2″ title=”Conference Banquet”/>
 <display:column property=”paperid” title=”Paper id”/>
 <display:column property=”tut_role” title=”Tutorial Identity”/>
 <display:column property=”tutorial” title=”Tutorial”/>
</display:table>

<br><br>

<p align=”center”>
Generated by Mango Conference System
</p>
</body>
</html>

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: