学习 JavaWeb项目开发案例精粹14(新闻发布系统)之十一

其实整个项目属java的部分差不多了,现在写一个整体的测试。

新在com.ppcms.common包下建一个Testt.java类

package com.ppcms.common;


import com.ppcms.common.*;
import com.ppcms.vo.*;

import java.sql.ResultSet;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.Iterator;
import java.util.Vector;

public class Testt
{

    public Testt()
    {
        sqlo = null;
    }

    public Iterator listNews(int newsId)
    {
        ResultSet rs = null;
        if(sqlo == null)
            sqlo = new SqlOperator();
        Vector vector = new Vector();
        String strSql = "select * from news where newsId=?;";
        try
        {
            sqlo.prepareStatement(strSql);
            sqlo.setInt(1, newsId);
            rs = sqlo.executeQuery();
            try
            {
                while(rs.next()) 
                {
                    News news = new News();
                    news.setNewsId(rs.getInt("newsId"));
                    news.setClassId(rs.getInt("classId"));
                    news.setKindId(rs.getInt("kindId"));
                    news.setMyOther(rs.getInt("myOther"));
                    news.setHeadTitle(rs.getString("headTitle"));
                    news.setContent(rs.getString("content"));
                    news.setConnect(rs.getString("connect"));
                    news.setAuthor(rs.getString("author"));
                    news.setEditor(rs.getString("editor"));
                    news.setNewsFrom(rs.getString("newsFrom"));
                    news.setHits(rs.getInt("hits"));
                    news.setNewsTime(rs.getString("newsTime"));
                    vector.add(news);
                }
                rs.close();
            }
            catch(NullPointerException nullE)
            {
                System.out.print("NewsShow newNews() " + nullE.getMessage());
                Debug.writeLog("NewsShow newNews(), Exception Occured ! Info :" + nullE.getLocalizedMessage());
            }
        }
        catch(SQLException sqlE)
        {
            System.out.print("NewsShow newNews() " + sqlE.getMessage());
            Debug.writeLog("NewsShow newNews(), Exception Occured ! Info :" + sqlE.getLocalizedMessage());
        }
        finally
        {
            sqlo.Close();
        }
        return vector.iterator();
    }

    public SqlOperator sqlo;
}
再建一个Testt.jsp

<%@ page contentType="text/html;charset=GBK"%>
<%@ page import="java.sql.*" %>
<%@ page import="java.util.*" %>
<%@ page import="com.ppcms.vo.*" %>

<jsp:useBean id="Testt" class="com.ttcmsv1.common.Testt"/>
<jsp:useBean id="servlet" scope="page" class="com.ppcms.servlet.DOServlet"/>


<body>
以下是文章内容:
<hr>
<%
    Iterator rs=Testt.listNews(servlet.requestInt(request,"newsId"));
			while(rs.hasNext()){
				News news = (News)rs.next();
			
				
%>
出处:<%=news.getNewsFrom()%><br>
作者:<%=news.getAuthor()%><br>
编辑:<%=news.getEditor()%><br>
内容: <%=news.getContent()%>
<% 
}
%>

</body>
发布,测试如图:
学习 JavaWeb项目开发案例精粹14(新闻发布系统)之十一_第1张图片


你可能感兴趣的:(学习 JavaWeb项目开发案例精粹14(新闻发布系统)之十一)