Detailed explanation of Web development news publishing system and web news publishing system

Source: Internet
Author: User

Detailed explanation of Web development news publishing system and web news publishing system
The software used in the press release system is:
(1) Myeclipse
(2) Mysql
1. Now, a project named news is created in myeclipse.
The first feature I made first is the login feature.


Login function:

You need to connect to the database for information interaction between the client and the server.

When I started to write the login function, I also encountered many problems, such as unable to connect to the database, but could not read the information in the database.

The login write function was written on the jsp page at the beginning, and later I learned that this is not good, although it is very simple, but if the project grows, you will find in the jsp page

There will be a lot of repeated code. So you can write the repeated code to the java code and call it on the jsp page.

Second, page beautification:

Login page at the beginning:


The login page is later:


The difference is that the HTML + CSS style is added to login. jsp. If you want to make your page more beautiful and dazzling,

You can learn about HTML + CSS and js scripts. You can also find some good styles on the Internet for reference.


Code:

1. login. jsp

<Span style = "font-size: 18px;"> <% @ page language = "java" import = "java. util. * "pageEncoding =" UTF-8 "%> <% String path = request. getContextPath (); String basePath = request. getScheme () + ": //" + request. getServerName () + ":" + request. getServerPort () + path + "/"; %> <! Doctype html public "-// W3C // dtd html 4.01 Transitional // EN"> 


2. Operation page

If you successfully log on to the index. jsp page, and fail to jump to the error. jsp page

DoLogin. jsp

<%@ page language="java" import="java.util.*" pageEncoding="gbk"%><%@page import="java.sql.*"%><%@page import="gxs.bzu.com.JDBC.*"%><%request.setCharacterEncoding("gbk");String uname=request.getParameter("uname");String upass=request.getParameter("upass");    Login login =new Login();boolean flag = login.get_UserAndPassword(uname, upass);out.print(flag);    if(flag){   response.sendRedirect("index.jsp");}else       response.sendRedirect("error.jsp");%>

3. java implementation and database connection code

Login. java

Import java. SQL. *; import java. util. *; public class Login {public boolean get_UserAndPassword (String name, String pass) {Connection conn = null; PreparedStatement pstmt = null; ResultSet rs = null; boolean flag = false; try {// 1. to register the driver, you must load the driver package Class. forName ("com. mysql. jdbc. driver ");} catch (ClassNotFoundException e) {System. out. println ("no driver found");} try {conn = DriverManager. getConnection ("jdbc: my SQL: // localhost: 3306/news "," root "," 123456 "); String SQL =" select * from userinfo where uname =? And upass =? "; Pstmt = conn. prepareStatement (SQL); // pre-compiled SQL statement pstmt. setString (1, name); pstmt. setString (2, pass); rs1_pstmt.exe cuteQuery (); if (rs. next () {flag = true ;}} catch (SQLException e) {e. printStackTrace ();} finally {try {if (rs! = Null) rs. close (); if (pstmt! = Null) pstmt. close (); if (conn! = Null) conn. close () ;}catch (SQLException e) {e. printStackTrace () ;}} return flag ;}}






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.