如何传输控制台上显示的输出并对其进行格式化以使其显示在网页上?
package collabsoft.backlog_reports.c4;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.Statement;
//import collabsoft.backlog_reports.c4.Report;
public class Report {
private Connection con;
public Report(){
connectUsingJDBC();
}
public static void main(String args[]){
Report dc = new Report();
dc.reviewMeeting(6, 8, 10);
dc.createReport("dede",100);
//dc.viewReport(100);
// dc.custRent(3344,123,22,11-11-2009);
}
/**
the following method is used to connect to the database
**/
public void connectUsingJDBC() {
// This is the name of the ODBC data source
String dataSourceName = "Simple_DB";
try {
// loading the driver in the memory
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
// This is the connection URL
String dbURL = "jdbc:odbc:" + dataSourceName;
con = DriverManager.getConnection("jdbc:mysql://localhost:3306/Collabsoft","root","");
// This line is used to print the name of the driver and it would throw an exception if a problem occured
System.out.println("User connected using driver: " + con.getMetaData().getDriverName());
//Addcustomer(con,1111,"aaa","aaa","aa","aam","111","2222","111");
//rentedMovies(con);
//executePreparedStatement(con);
//executeCallableStatement(con);
//executeBatch(con);
} catch (Exception e) {
e.printStackTrace();
}
}
/**
*this code is to link the SQL code with the java for the task
*as an admin I should be able to create a report of a review meeting including notes, tasks and users
*i will take the task id and user id and note id that will be needed to be added in the review
*meeting report and i will display the information related to these ida
**/
public void reviewMeeting(int taskID, int userID, int noteID)// law el proc bt return table
{
try{
CallableStatement callableStatement = con.prepareCall("{CALL report_review_meeting(?,?,?)}");
callableStatement.setInt(1,taskID);
callableStatement.setInt(2,userID);
callableStatement.setInt(3,noteID);
ResultSet resultSet = callableStatement.executeQuery(); // or executeupdate() or updateQuery
ResultSetMetaData rsm = resultSet.getMetaData();
int numOfColumns = rsm.getColumnCount();
System.out.println("lojayna");
while (resultSet.next())
{
System.out.println("New Row:");
for (int i = 1; i <= numOfColumns; i++)
System.out.print(rsm.getColumnName(i) + ": " + resultSet.getObject(i) + " ");
System.out.println();
}
}
catch(Exception e)
{
System.out.println("E");
}
}
//////////////////////////////////
/////////////////////////////////
public void allproject(int projID)// law el proc bt return table
{
try{
CallableStatement callableStatement = con.prepareCall("{CALL all_project(?)}");
callableStatement.setInt(1,projID);
//callableStatement.setInt(2,userID);
//callableStatement.setInt(3,noteID);
ResultSet resultSet = callableStatement.executeQuery(); // or executeupdate() or updateQuery
ResultSetMetaData rsm = resultSet.getMetaData();
int numOfColumns = rsm.getColumnCount();
System.out.println("lojayna");
while (resultSet.next())
{
System.out.println("New Row:");
for (int i = 1; i <= numOfColumns; i++)
System.out.print(rsm.getColumnName(i) + ": " + resultSet.getObject(i) + " ");
System.out.println();
}
}
catch(Exception e)
{
System.out.println("E");
}
}
///////////////////////////////
/**
* here i take the event id and i take a string report and then
* i relate the report with the event
**/
public void createReport(String report,int E_ID )// law el proc bt return table
{
try{
Statement st = con.createStatement();
st.executeUpdate("UPDATE e_vent SET e_vent.report=report WHERE e_vent.E_ID= E_ID;");
/* CallableStatement callableStatement = con.prepareCall("{CALL Create_report(?,?)}");
callableStatement.setString(1,report);
callableStatement.setInt(2,E_ID);
ResultSet resultSet = callableStatement.executeQuery(); // or executeupdate() or updateQuery
ResultSetMetaData rsm = resultSet.getMetaData();
int numOfColumns = rsm.getColumnCount();
System.out.println("lojayna");
while (resultSet.next())
{
System.out.println("New Row:");
for (int i = 1; i <= numOfColumns; i++)
System.out.print(rsm.getColumnName(i) + ": " + resultSet.getObject(i) + " ");
System.out.println();
}*/
}
catch(Exception e)
{
System.out.println("E");
System.out.println(e);
}
}
/**
*in the following method i view the report of the event having the ID eventID
**/
public void viewReport(int eventID)// law el proc bt return table
{
try{
CallableStatement callableStatement = con.prepareCall("{CALL view_report(?)}");
callableStatement.setInt(1,eventID);
ResultSet resultSet = callableStatement.executeQuery(); // or executeupdate() or updateQuery
ResultSetMetaData rsm = resultSet.getMetaData();
int numOfColumns = rsm.getColumnCount();
System.out.println("lojayna");
while (resultSet.next())
{
System.out.println("New Row:");
for (int i = 1; i <= numOfColumns; i++)
System.out.print(rsm.getColumnName(i) + ": " + resultSet.getObject(i) + " ");
System.out.println();
}
}
catch(Exception e)
{
System.out.println("E");
}
}
}
// 这些方法的结果显示在控制台上,我正在使用 WIcket,我希望它 2 显示在网络上 这是怎么做到的?!
package collabsoft.backlog_reports.c4;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.Statement;
//import collabsoft.backlog_reports.c4.Report;
public class Report {
private Connection con;
public Report(){
connectUsingJDBC();
}
public static void main(String args[]){
Report dc = new Report();
dc.reviewMeeting(6, 8, 10);
dc.createReport("dede",100);
//dc.viewReport(100);
// dc.custRent(3344,123,22,11-11-2009);
}
/**
the following method is used to connect to the database
**/
public void connectUsingJDBC() {
// This is the name of the ODBC data source
String dataSourceName = "Simple_DB";
try {
// loading the driver in the memory
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
// This is the connection URL
String dbURL = "jdbc:odbc:" + dataSourceName;
con = DriverManager.getConnection("jdbc:mysql://localhost:3306/Collabsoft","root","");
// This line is used to print the name of the driver and it would throw an exception if a problem occured
System.out.println("User connected using driver: " + con.getMetaData().getDriverName());
//Addcustomer(con,1111,"aaa","aaa","aa","aam","111","2222","111");
//rentedMovies(con);
//executePreparedStatement(con);
//executeCallableStatement(con);
//executeBatch(con);
} catch (Exception e) {
e.printStackTrace();
}
}
/**
*this code is to link the SQL code with the java for the task
*as an admin I should be able to create a report of a review meeting including notes, tasks and users
*i will take the task id and user id and note id that will be needed to be added in the review
*meeting report and i will display the information related to these ida
**/
public void reviewMeeting(int taskID, int userID, int noteID)// law el proc bt return table
{
try{
CallableStatement callableStatement = con.prepareCall("{CALL report_review_meeting(?,?,?)}");
callableStatement.setInt(1,taskID);
callableStatement.setInt(2,userID);
callableStatement.setInt(3,noteID);
ResultSet resultSet = callableStatement.executeQuery(); // or executeupdate() or updateQuery
ResultSetMetaData rsm = resultSet.getMetaData();
int numOfColumns = rsm.getColumnCount();
System.out.println("lojayna");
while (resultSet.next())
{
System.out.println("New Row:");
for (int i = 1; i <= numOfColumns; i++)
System.out.print(rsm.getColumnName(i) + ": " + resultSet.getObject(i) + " ");
System.out.println();
}
}
catch(Exception e)
{
System.out.println("E");
}
}
//////////////////////////////////
/////////////////////////////////
public void allproject(int projID)// law el proc bt return table
{
try{
CallableStatement callableStatement = con.prepareCall("{CALL all_project(?)}");
callableStatement.setInt(1,projID);
//callableStatement.setInt(2,userID);
//callableStatement.setInt(3,noteID);
ResultSet resultSet = callableStatement.executeQuery(); // or executeupdate() or updateQuery
ResultSetMetaData rsm = resultSet.getMetaData();
int numOfColumns = rsm.getColumnCount();
System.out.println("lojayna");
while (resultSet.next())
{
System.out.println("New Row:");
for (int i = 1; i <= numOfColumns; i++)
System.out.print(rsm.getColumnName(i) + ": " + resultSet.getObject(i) + " ");
System.out.println();
}
}
catch(Exception e)
{
System.out.println("E");
}
}
///////////////////////////////
/**
* here i take the event id and i take a string report and then
* i relate the report with the event
**/
public void createReport(String report,int E_ID )// law el proc bt return table
{
try{
Statement st = con.createStatement();
st.executeUpdate("UPDATE e_vent SET e_vent.report=report WHERE e_vent.E_ID= E_ID;");
/* CallableStatement callableStatement = con.prepareCall("{CALL Create_report(?,?)}");
callableStatement.setString(1,report);
callableStatement.setInt(2,E_ID);
ResultSet resultSet = callableStatement.executeQuery(); // or executeupdate() or updateQuery
ResultSetMetaData rsm = resultSet.getMetaData();
int numOfColumns = rsm.getColumnCount();
System.out.println("lojayna");
while (resultSet.next())
{
System.out.println("New Row:");
for (int i = 1; i <= numOfColumns; i++)
System.out.print(rsm.getColumnName(i) + ": " + resultSet.getObject(i) + " ");
System.out.println();
}*/
}
catch(Exception e)
{
System.out.println("E");
System.out.println(e);
}
}
/**
*in the following method i view the report of the event having the ID eventID
**/
public void viewReport(int eventID)// law el proc bt return table
{
try{
CallableStatement callableStatement = con.prepareCall("{CALL view_report(?)}");
callableStatement.setInt(1,eventID);
ResultSet resultSet = callableStatement.executeQuery(); // or executeupdate() or updateQuery
ResultSetMetaData rsm = resultSet.getMetaData();
int numOfColumns = rsm.getColumnCount();
System.out.println("lojayna");
while (resultSet.next())
{
System.out.println("New Row:");
for (int i = 1; i <= numOfColumns; i++)
System.out.print(rsm.getColumnName(i) + ": " + resultSet.getObject(i) + " ");
System.out.println();
}
}
catch(Exception e)
{
System.out.println("E");
}
}
}
// the result of these methods is being showed on the console , i am using WIcket and i want it 2 be showed on the web how is that done ?!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您只想将文本转储到 html 页面,请使用 StringBuilder 和/或创建一个额外的类,其中包含使用 html 标签输出文本的方法。
如果您确实想要为网站制作动画,最“简单”的方法是使用 Servlet。请参阅下面的链接获取教程。
http://www.java-servlets-with-eclipse.html java-tips.org/java-tutorials/tutorials/introduction-to-java-servlets-with-eclipse.html
If you want to do is simply dump text to an html page, use a StringBuilder and/or create an extra class with methods to ouput text with html tags.
If you actually want to animate a web site, the most "simple" way would be to use Servlets. See the link below for a tutorial.
http://www.java-tips.org/java-tutorials/tutorials/introduction-to-java-servlets-with-eclipse.html
如果你想要简单的解决方案,请看詹姆斯的回答。但是,如果您需要在应用程序甚至平台之间异步传输数据(如果它们不是本地的,则需要双倍传输),您可能需要查看 JMS api(当您使用 Glassfish 作为应用程序服务器时,这非常简单,或者 Apache ActiveMQ 实现做得很好)。我在部署中使用它,其中从 webapp 调用系统程序/脚本,然后这些程序在完成时通过 JMS 向 webapp 报告。
或者,您也可以将该输出转储到数据库。
If you want simple solution go with James' answer. However if you need to asynchronously transfer data between applications or even platforms (double-time when they are not local), you may want to look into JMS api (when you are using Glassfish as application server it's quite easy or Apache ActiveMQ implementation does good job). I'm using it in deployment where system programs/scripts are called from webapp and then these programs report back to webapp via JMS when they finish.
Alternatively you can dump that output to database as well.