A complete press release system
Keywords: JSP, Java, Press Release Environment: Tomcat 5.5.7 J2se 5.0 PostgreSQL 8.0
I will take a few steps to complete the build of a press release system, understand some basic methods of JSP!
First of all, I will first introduce the basic structure of this press release system:
Index.jsp: Admin Land Interface Check.jsp: Verify Administrator identity main.jsp: Administrator adds news page Pub.jsp: Page Display: Show all news
The background of the background is mainly:
DB.java: Database Connection MD5.java: MD5 Algorithm Pubbean.java: Release CheckBean.java: Verify login identity
That is, you can complete the basic feature of a press release system when you go from index -> main-> display.
I don't write the title and content of the news to the database, because the resources of the database system are too expensive, and the number is always read when visiting
According to the library, it is very hard, I wrote the news into a separate HTM file, then written the title and the name of the HTM file!
And how does the name of this HTM file are randomly generated? I chose the MD5 algorithm because the title of each news will not be the same, so the only one is guaranteed.
Sex!
Below I first put out the basic framework of this system, saying big, it seems to be the "system" "kernel"! :)
================ Database section ===================
Create Table Administrator (Admin Char (16), "Password" CHAR (32)) WITHOUT OIDS; ALTER TABLE Administrator Owner To Admin;
Create Table News (Title Char (255), Page CHAR (255)) WITHOUT OIDS; ALTER TABLE NEWNER TO Admin Admin
================ Program part ==================
Package login;
Import java.sql. *;
Public class db {
Private connection conn; private resultset {type {class.forname ("org.postgreSql.driver); conn = drivermanager.getConnection
("JDBC: PostgreSQL: // LocalHost: 5432 / News? User = admin"); stmt = conn.createstatement ();} catch (exception e) {system.out.println (e);}} public void update (String SQL) {Try {stmt.executeUpdate (SQL);} catch (exception e) {system.out.println (e);}} public resultset quarry (String SQL) {Try {= stmt.executeQuery (SQL) Catch (Exception E) {system.out.println (e);} RETURN RS;}} package login
Import java.sql. *; import java.io. *;
Public class pubbean {private limited title, context; private db db; private md5 md5; public pubbean () {db = new db (); md5 = new md5 ();} public void settitle (String title) {this.title = PUBLIC VOID SETCONTEXT (STRING CONTEXT) {this.context = context;}
Public void Pubit () {TRY {Title = New String (Title.getbytes ("8859_1"), "GB2312"); Context = New String (Context.getbytes ("8859_1"), "GB2312"); string titlemd5 = MD5 .getKeyBeanofstr (Title); DB.Update (" Title ", '" TitleMd5 ") "); string file =" news // Ice " titlemd5 ". htm "; PrintWriter PW = new printstream (file); PW.Println ("
Package login;
Import java.sql. *;
public class CheckBean {private String message = "", admin, password; private DB db; public CheckBean () {db = new DB ();} public void setAdmin (String admin) {this.admin = admin;} public void setPassword (String password) {this.password = password;} public string checkit () {Try {resultset = db.quarry ("Select * from administrator whereadmin = ' this.admin "); while (rs.next ()) {String PWS = rs.getstring ("password"). Trim (); if (this.paals (this.pals (this.pals)) {message = "Password is correct!";} Else message = "Password error!" Return Message;} Message = "Users do not exist!";} catch (exception e) {system.out.println (e);} returnome
================ page part ===================
INDEX.JSP:
<% @ Page ContentType = "Text / HTML; Charset = GB2312"%>