0

我有以下java代码:

import java.sql.Connection;   
import java.sql.DriverManager;   
import java.sql.ResultSet;   
import java.sql.Statement;


public class License {   
    public static void main(String[] args) {   

        Connection connection = null;   
        ResultSet resultSet = null;   
        Statement statement = null;   

        try {   
            Class.forName("org.sqlite.JDBC");   
            connection = DriverManager.getConnection("jdbc:sqlite:C:/license_tracker/usage.db3");   
            statement = connection.createStatement(); 
            System.out.println("Connection Successful!!!!");
            String query = "SELECT  USR.id,USR.name, ST.license FROM users USR, status ST, upd_ate UD WHERE UD.upt_id = (select max(p2.upt_id) from upd_ate p2) AND ST.id = USR.id AND ST.upt_id = UD.upt_id ORDER BY ST.license,USR.name";

            resultSet = statement.executeQuery(query);  

            while (resultSet.next()) { 

                System.out.printf("%8s   %-50s   %-7s%n",resultSet.getString("cymer_id"), resultSet.getString("name"), resultSet.getString("license"));   

            }   
        } catch (Exception e) {   
            e.printStackTrace();   
        } finally {   
            try {   
                resultSet.close();   
                statement.close();   
                connection.close();   
            } catch (Exception e) {   
                e.printStackTrace();   
            }   
        }   
    }   
}

我想在 Web 浏览器(本质上是 IE9)中以表格格式显示结果集的内容。我已经对此进行了搜索,我认为有两种选择,使用 JAVA 小程序或 JSP。由于我必须在服务器上运行代码,我应该使用 JSP 吗?我对 JSP 不太熟悉,所以如果有人能帮助我,我将不胜感激。我正在使用 Eclipse Indigo 并拥有 Tomcat 版本 7。

我在网页布局上有一个 html 代码。我想把信息放在表格里。

<!DOCTYPE html>

<html>


<head>


<!-- FORMAT OF THE BOXES //-->
<style type="text/css">

div.ex
{
width:360px;height:300px;
padding:10px;
border:5px solid gray;
margin:0px;
background-color:linen;}

    div.graph
{
width:800px;height:300px;
padding:10px;
border:5px solid gray;
margin:0px;
background-color:linen;}


</style>





</head>


<body>




<!--h1=> LOGO & h2=> Heading //-->




<h2 style="text-align:center;font-family:century schoolbook;color:black";><b>Pro/Engineer And Intralink License Logs</b></h2>



<!-- License summary bar //-->
<div id="content" style="background-color:mediumpurple;clear:both;text-align:center;"><big>License Summary</big></div>

<!-- TABLES //-->
<center>
<table cellspacing="5" border="0" cellpadding="0">



 <td><p><div class="ex"><center>DESIGNER LICENSES</center><br/></p></td>


 <td width="2" bgcolor=black><BR></td>
 <td>
 <p><div class="ex"><center>LEAD LICENSES</center><br/></p>
 </td>


 <td width="2" bgcolor=black><BR></td>
 <td>
 <p><div class="ex"><center>CABLING LICENSES</center><br/></p>
 </td>


 <td width="2" bgcolor=black><BR></td>
 <td>
 <p><div class="ex"><center>LICENSES</center><br/></p>
 </td>


 </table> 
</center>

<!-- GRAPH SPACE //-->
 <p><div class="graph"><center>GRAPHICAL REPRESENTATION</center></div></p>




</body>



<hr/>
<center><style=padding:100px;>



<!-- FOOTER //-->
<footer>
<div id="donotremove">
    <abbr title="License Availability (v1 on 32)">License Availability</abbr> © 2011-2351  All rights reserved.</a>.</div></footer>
</center>



</html>
4

2 回答 2

1

创建jsp文件。

有关 jsp 示例,请参见此链接

或者

使用servlet.

有关 servlet 示例,请参见此链接

或者

利用jsf

请参阅此链接以获取 jsf 示例。

它会帮助你。

于 2012-06-18T18:36:14.497 回答
1

也许你可以做这样的事情:

import java.io.*;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class LicenseServlet extends HttpServlet {

public void doGet(HttpServletRequest request,
                    HttpServletResponse response)
      throws ServletException, IOException {
        PrintWriter out = response.getWriter();

        out.print("<html><body><table>");

        // ... pseudocode
        while (resultSet.next()) { 
            out.print("<tr><td>");
            out.print("%8s   %-50s   %-7s%n",resultSet.getString("cymer_id"), resultSet.getString("name"), resultSet.getString("license"));   
            out.print("</td></tr>");

        } 


        out.print("</table></body></html>");
  }
}
于 2012-06-18T18:45:44.650 回答