Real-field JSP advanced programming One

Source: Internet
Author: User
Tags insert return string

Many JSP beginners in learning simple JSP programming, often stay in the JSP inside the SQL statement to tune a JavaBean database connection stage, stalled.

This simple tutorial is expected to help beginners learn to use OOP ideas for JSP programming.

Scenario: A simple news system that consists of 2-3 data tables.

The database system uses MySQL, and of course it is similar to others.

First datasheet, and the main data sheet: News

create table news2 (newsid int not null,
userid int,
kwid int, // 关键词外键
title varchar(100),
content text,
hits int,
cdate varchar2(30),
mdate varchar2(30),
primary key(newsid));

Insert one more sample data:

insert into news2 (newsid, title, content) values (1, 'test title', 'test body');

Design idea: Programming with MVC pattern, packing data in a helper class News.java,

And through the Newsdao.java database operation.

In the design phase, UML is used to sketch the object of the system.

... omitted here

The main methods of Newsdao are:

1. Public News getnewsbyprimarykey (int newsid);

2. Public news[] Getrecentnews ();

3. Public news[] Gethotnews ();

......

The code for News.java is as follows:

Package news;
public class News {
private int newsid;
private int userid;
private int kwid;
private int hits;
Private String title;
Private String content;
Private String CDate;
Private String mdate;
Public News () {}
Public News (int newsid,int userid,int kwid,int hits,string title,string content,string)
{
This.newsid=newsid;
This.userid=userid;
This.kwid=kwid;
This.hits=hits;
This.title=title;
This.content=content;
This.cdate=cdate;
}
public News (int ID, string t, string cnt) {
This.newsid = ID;
This.title = t;
This.content = CNT;
}
public int Getnewsid ()
{
return newsid;
}
public void Setnewsid (int newsid)
{
This.newsid=newsid;
}
public int GetUserID ()
{
return userid;
}
public void Setuserid (int userid)
{
This.userid=userid;
}
public int Getkwid ()
{
return kwid;
}
public void Setkwid (int kwid)
{
This.kwid=kwid;
}
public int gethits ()
{
return hits;
}
public void sethits (int hits)
{
This.hits=hits;
}
Public String GetTitle ()
{
return title;
}
public void Settitle (String title)
{
This.title=title;
}
Public String getcontent ()
{
return content;
}
public void SetContent (String content)
{
This.content=content;
}
Public String getcdate ()
{
return cdate;
}
public void Setcdate (String cdate)
{
This.cdate=cdate;
}
}

Description: This program can be used as JavaBean, as a parameter carrier for entry form (params Holder).



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.