Java Web Learning Communication Network (IMITATING Baidu Post Bar) I. Tutorial Purpose
1. Connect to the MySQL database
2. Read the database to the web page
Ii. Lab requirements
1. Design a post bar so that users can register, ask, and answer
3. experiment step 1. Test preparation
A. Install mysql
B. Install navicat
C. Introduce the MySQL jar package to MyEclipse.
2. Function Structure
3. Design a database
A defines three tables.
User (uid, name)
Question (qid, uid, title, content, time)
Answer (aid, qid, uid, content, time)
B. analyze the relationship between the three using the e-r Diagram
C database code
Create database tb; use tb; // create table user (uid int (10) not null AUTO_INCREMENT, name varchar (20) not null, primary key (UID )) ENGINE = innodb default charset = gb2312; create table question (qid int (10) not null AUTO_INCREMENT, uid int (10), title varchar (20), content varchar (100) not null, time varchar (15) not null, foreign key (UID) references user (UID), primary key (QID) ENGINE = innodb default charset = gb2312; Create table answer (aid int (10) not null AUTO_INCREMENT, qid int (10), uid int (10), content varchar (200) not null, time varchar (15) not null, foreign key (QID) references question (QID), foreign key (UID) references user (UID), primary key (AID, QID )) ENGINE = innodb default charset = gb2312; // INSERT data into user (UID, NAME) VALUES (1, 'zhang san'), (2, 'Li si'), (3, 'wang 5'); insert into question (QID, UID, TITLE, CONTENT, TIME) VALUES (, 'Count', '1 + 1 =? ', '2014-3-2'), (2014, 'Weather ', 'Today's sunny day? ', '2014-3-7'), (2014, 'date', 'Day of the week tomorrow? ', '2014-3-9'), (2014, 'Weather ', 'How many degrees after tomorrow? ', '2014-4-5'); insert into answer (AID, QID, UID, CONTENT, TIME) VALUES (2014, 2, 'Sunday today ', '2017-3-7'), (2014, 3, 'Sunday today ', '2017-3-7'), (2014, 2, '1 + 1 = 2 ', '2014-3-10 '), (2014-3, 3, '1 + 1 = 2', '2014-3-17'), (2014, 2, 'tuesday today ', '2014-3-11 '), (2014, 1, '20 ', '2014-4-5 '); SELECT * from userselect * from questionselect * FROM ANSWER
4. Design a java web Page
A creates three jsp pages (register. jsp login. jsp show. jsp question. jsp answer. jsp)
B. Specific implementation ideas:
1) first design the register. jsp page,
2) After the user registration is successful, the user directly enters login. jsp,
3) log on to the index. jsp page. Index. jsp is mainly used to display storage issues in the database. In the "management" column,"View"Or"Browse"(Hyperlink ).
4) When you click"View"When the page is redirected to the question. jsp page (when the page is redirected, the id parameter of question is included ).Question title,Release Date,DetailsAndUser Information, The problem is as follows:View the answer connection.
5) when the answer button is clicked, the page jumps to answer. jsp (with the Question id), answer. the first task on the jsp page is to display the number of answers to the specified question. The second task is to list the answer content, the respondent information, and the answer time. The third task is, design at the bottomAdd an answer form, And its action = "addAnswer. jsp ".
6) addAnswer. jsp processing answer. the answer data submitted by the jsp form is returned within 5 seconds after the processing is correct. Step 1 (previous step) shows the latest data on the answer page (one more answer can be seen ). Returned error to the previous page (YesTryRemember the last input data ).
Note: At the same time, each page can be returned to the home page.
(Refer to textbook project 6.3 --- Book Management System)