易理解简单的Javaweb新闻发布系统(含增删改查以及登入注册包含mysql建表语句)

原作者Lonely_survivor 稍作修改一方,如有侵权原作,可私信我,立刻删除(大二学生满满的求生欲)

废话不多说,项目表

数据库连接DBConnection.java

package news;
import java.sql.*;
/**
 * 
 * @author Administrator
 *
 */
public class DBConnection {
    private String driverStr="com.mysql.jdbc.Driver";
    private String connStr="jdbc:mysql://localhost:3306/news";
    private String dbusername="root";
    private String dbpassword="111111";
    private Connection conn=null;
    private Statement stmt=null;
    public DBConnection(){
        try{
            Class.forName(driverStr);
            System.out.println("数据库连接成功!");
            conn=DriverManager.getConnection(connStr,dbusername,dbpassword);
            stmt=conn.createStatement();
        }catch(Exception ex){System.out.println("无法同数据库建立连接");}
    }
    public int executeUpdate(String s){
        int result=0;
        try{
            result=stmt.executeUpdate(s);
        }catch(Exception ex){System.out.println("执行更新失败");}
        return result;
    }
    public ResultSet executeQuery(String s){
        ResultSet rs=null;
        try{
            rs=stmt.executeQuery(s);
        }catch(Exception ex){System.out.println("执行查询失败");}
        return rs;
    }
    public void close(){
        try{
            stmt.close();
            conn.close();
        }catch(Exception ex){System.out.println("数据库关闭失败");}
    }
}

 新闻控制器newsController.java

package news;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;


import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.servlet.*;
/**
 * Servlet implementation class newsController
 */
@WebServlet(name="/newsController",urlPatterns= {"*.do"})
public class newsController extends HttpServlet {
    private static final long serialVersionUID = 1L;

    /**
     * @see HttpServlet#HttpServlet()
     */
    public newsController() {
        super();
        // TODO Auto-generated constructor stub
    }

    /**
     * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setContentType("text/html;charset=GBK");
        PrintWriter out = response.getWriter();
        request.setCharacterEncoding("GBK");
        String actionUrl = request.getServletPath();
        if (actionUrl.equals("/checkName.do")) {// 检查用户名是否可用
            String username = request.getParameter("username");
            boolean exist = UserInfo.checkName(username);
            if (exist)
                request.getRequestDispatcher("/userExist.html").forward(request, response);
            else
                request.getRequestDispatcher("/userUnexist.html").forward(request, response);
        } else if (actionUrl.equals("/register.do")) {
            String username = request.getParameter("username");
            String pwd = request.getParameter("pwd");
            String sex = request.getParameter("sex");
            String email = request.getParameter("email");
            int i = UserInfo.userRegister(username, pwd, sex, email);
            if (i == 1)
                request.getRequestDispatcher("/regSuccess.jsp").forward(request, response);
            else
                request.getRequestDispatcher("/regFailure.jsp").forward(request, response);
        } else if (actionUrl.equals("/login.do")) {
            String username = request.getParameter("username");
            String pwd = request.getParameter("pwd");
            boolean exist = UserInfo.userLogin(username, pwd);// 登陆函数
            if (exist) {
                request.getSession().setAttribute("username", username);
                request.getRequestDispatcher("/index.jsp").forward(request, response);
            } else {
                request.getRequestDispatcher("/logFailure.jsp").forward(request, response);
            }
        } else if (actionUrl.equals("/password.do")) {
            String username = (String) request.getSession().getAttribute("username");
            String pwd = request.getParameter("pwd");
            int i = UserInfo.pwdEdit(username, pwd);
            if (i == 1)
                request.getRequestDispatcher("/success.jsp").forward(request, response);
            else
                request.getRequestDispatcher("/failure.jsp").forward(request, response);
        } else if (actionUrl.equals("/add.do")) {// 获取地址为新闻入库add.do
            String name = request.getParameter("name");
            String author = request.getParameter("author");
            String time = request.getParameter("time");
            String source = request.getParameter("source");
            String type = request.getParameter("type");
            String quantity = request.getParameter("quantity");
            int result = NewsInfo.addNews(name, author, time, source, type, quantity);
            if (result == 1)
                request.getRequestDispatcher("/success.jsp").forward(request, response);
            else
                request.getRequestDispatcher("/failure.jsp").forward(request, response);
        } else if (actionUrl.equals("/list.do")) {// 获取地址为新闻入库list.do
            ArrayList<NewsInfo> list = NewsInfo.getNewsList();// 获取所有的新闻信息
            request.setAttribute("list", list);
            request.getRequestDispatcher("/list.jsp").forward(request, response);
        } else if (actionUrl.equals("/edit.do")) {
            String id = request.getParameter("id");
            NewsInfo bi = NewsInfo.getNewsById(id);
            request.setAttribute("bi", bi);
            request.getRequestDispatcher("/ediit.jsp").forward(request, response);
        } else if (actionUrl.equals("/update.do")) {
            String id = request.getParameter("id");
            String name = request.getParameter("name");
            String author = request.getParameter("author");
            String time = request.getParameter("time");
            String source = request.getParameter("source");
            String type = request.getParameter("type");
            String quantity = request.getParameter("quantity");
            int i = NewsInfo.updateNews(id, name, author, time, source, type, quantity);
            if (i == 1)
                request.getRequestDispatcher("/success.jsp").forward(request, response);
            else
                request.getRequestDispatcher("/failure.jsp").forward(request, response);
        } else if (actionUrl.equals("/del.do")) {// 获得的地址为删除新闻del.do
            String id = request.getParameter("id");
            int i = NewsInfo.delNews(id);
            if (i == 1)
                request.getRequestDispatcher("/success.jsp").forward(request, response);
            else
                request.getRequestDispatcher("/failure.jsp").forward(request, response);
        } 
    }

    /**
     * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
        doGet(request, response);
    }
}

新闻信息NewsInfo.java

package news;
import java.util.*;
import java.sql.*;
import java.sql.Date;
/**
 * 
 * @author Administrator
 *
 */
public class NewsInfo {
     private String id;
        private String name;
        private String author;
        private Date time;
        private String source;
        private String type;
        private int quantity;
        public NewsInfo() {}

      //添加
        public static int addNews(String name,String author,String time,String source,String type,String quantity){
            int result=0;
            String sql="insert into newsinfo(name,author,time,source,type,quantity) values('"+name+"','"+author+"','"+time+"','"+source+"','"+type+"','"+quantity+"')";
            DBConnection db=new DBConnection();
            result=db.executeUpdate(sql);
            return result;
        }
        
        
        //显示
        public static ArrayList<NewsInfo> getNewsList(){
        	ArrayList<NewsInfo> list=new ArrayList<NewsInfo>();//list存储记录
        	DBConnection db=new DBConnection();
        	String sql="select * from newsinfo";
   
            ResultSet rs=db.executeQuery(sql);
            try{
                while(rs.next()){
                    NewsInfo bi=new NewsInfo();
                    bi.setName(rs.getString("name"));//对新闻bi进行设置
                    bi.setAuthor(rs.getString("author"));
                    bi.setTime(rs.getDate("time"));
                    bi.setSource(rs.getString("source"));
                    bi.setType(rs.getString("type"));
                    bi.setQuantity(rs.getInt("quantity"));
                    bi.setId(rs.getString("id"));
                    list.add(bi);
                }
            }catch(Exception e){e.printStackTrace();}
            return list;
        }
        
        
        //通过id获取新闻记录
        public static NewsInfo getNewsById(String id){
            String sql="select * from newsinfo where id='"+id+"'";
            DBConnection db=new DBConnection();
            ResultSet rs=db.executeQuery(sql);
            NewsInfo bi=new NewsInfo();
            try{
                if(rs.next()){
                    bi.setId(rs.getString("id"));
                    bi.setName(rs.getString("name"));
                    bi.setAuthor(rs.getString("author"));
                    bi.setTime(rs.getDate("time"));
                    bi.setSource(rs.getString("source"));
                    bi.setType(rs.getString("type"));
                    bi.setQuantity(rs.getInt("quantity"));
                }
            }catch(Exception e){e.printStackTrace();}
            return bi;
        }
        
        
        //修改
        public static int updateNews(String id,String name,String author,String time,String source,String type,String quantity){
            String sql="update newsinfo set name='"+name+"',author='"+author+"',time='"+time+"',source='"+source+"',type='"+type+"',quantity='"+quantity+"' where id='"+id+"'";
            DBConnection db=new DBConnection();
            int i=db.executeUpdate(sql);
            return i;
        }
        
        
        //删除
        public static int delNews(String id){
            String sql="delete from newsinfo where id='"+id+"'";
            DBConnection db=new DBConnection();
            int i=db.executeUpdate(sql);
            return i;
        }
     
        
        public String getId() {
            return id;
        }
        public void setId(String id) {
            this.id = id;
        }
        public String getName() {
            return name;
        }
        public void setName(String name) {
            this.name = name;
        }
        public String getAuthor() {
            return author;
        }
        public void setAuthor(String author) {
            this.author = author;
        }
        public Date getTime() {
            return time;
        }
        public void setTime(Date time) {
            this.time = time;
        }
        public String getSource() {
            return source;
        }
        public void setSource(String source) {
            this.source = source;
        }
        public String getType() {
            return type;
        }
        public void setType(String type) {
            this.type = type;
        }
        public int getQuantity() {
            return quantity;
        }
        public void setQuantity(int quantity) {
            this.quantity = quantity;
        }    
}

 用户信息UserInfo.java

package news;
import java.sql.*;
/**
 * 
 * @author Administrator
 *
 */
public class UserInfo {
    private String username;
    private String pwd;
    private String sex;
    private String email;

    public UserInfo() {
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPwd() {
        return pwd;
    }

    public void setPwd(String pwd) {
        this.pwd = pwd;
    }

    public String getSex() {
        return sex;
    }

    public void setSex(String sex) {
        this.sex = sex;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    
     //注册
    public static int userRegister(String username,String pwd,String sex,String email){
        int result=0;
        String sql="insert into user(username,pwd,sex,email) values('"+username+"','"+pwd+"','"+sex+"','"+email+"')";
        DBConnection db=new DBConnection();
        result=db.executeUpdate(sql);
        return result;
    }
    
    
    //登录
    public static boolean userLogin(String username,String pwd){
        boolean exist=false;
        String sql="select * from user where username='"+username+"' and pwd='"+pwd+"'";
        DBConnection db=new DBConnection();
        ResultSet rs=db.executeQuery(sql);
        try{
            if(rs!=null&&rs.next())
                exist=true;
        }catch(Exception e){
            System.out.println("查找用户失败!");
        }
        return exist;
    }
    
    
    //检查用户名是否可用函数
    public static boolean checkName(String username){
        boolean exist=false;
        String sql="select * from user where username='"+username+"'";
        DBConnection db=new DBConnection();
        ResultSet rs=db.executeQuery(sql);
        try{
            if(rs!=null&&rs.next())
                exist=true;
        }catch(Exception e){
            System.out.println("查找用户名失败!");
        }
        return exist;
    }
    
    
    //密码修改
    public static int pwdEdit(String username,String pwd){
        int result=0;
        String sql="update user set pwd='"+pwd+"' where username='"+username+"'";
        DBConnection db=new DBConnection();
        result=db.executeUpdate(sql);
        return result;
    } 
}

 数据库建表createTable.jsp

<%@ page language="java" contentType="text/html; charset=GBK"
    pageEncoding="GBK"%>
<%@page import="java.sql.*" %>
<jsp:useBean id="db" class="news.DBConnection" scope="page"/>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GBK">
<title>创建新闻表和用户表</title>
</head>
<body bgcolor="#ffddee">
    <center>
        <h1>新闻发布系统-表创建</h1>
        <hr>
        <form action="createTable.jsp" method="post">
            <input type="submit" name="submit" value="创建表">
        </form>
        <%
            request.setCharacterEncoding("GBK");
            String submit=request.getParameter("submit");
            if(submit!=null){
                String sql="create table if not exists newsinfo(id int(10) unsigned NOT NULL auto_increment,name varchar(20) NOT NULL default '',author varchar(45) NOT NULL default '',time date,source char(10) not null default '',type varchar(20) NOT NULL default '',quantity int(20),PRIMARY KEY (`id`))";
                String sql2="create table if not exists user(username varchar(20) primary key,pwd varchar(20) not null,sex char(2) not null,email varchar(20) not null)";
                int i=db.executeUpdate(sql);
                int j=db.executeUpdate(sql2);
                out.println("<script language='javascript'> alert('新闻表和用户表创建成功,点击确定返回首页');</script>");
                response.setHeader("refresh", "1;url=login.jsp");
            }
        %>
    </center>
    </body>
</html>

添加新闻addnews.jsp

<%@ page language="java" contentType="text/html; charset=GBK"
    pageEncoding="GBK"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GBK">
<title>新闻发布系统-新闻信息入库</title>
</head>
<body bgcolor="yellow">
        <%=session.getAttribute("username") %>同学,您好!欢迎来到新闻发布系统!
    <center>
        <h1>新闻发布系统-新闻信息入库</h1>
        <%@include file="header.jsp" %>
        <hr>
        <form action="add.do" method="post">
            <table border="1">
                <tr><th colspan="2">请输入新闻信息</th></tr>
                <tr><td>新闻标题:</td><td><input type="text" name="name"></td></tr>
                <tr><td>作者:</td><td><input type="text" name="author"></td></tr>
                <tr><td>发布时间:</td><td><input type="text" name="time"></td></tr>
                <tr><td>新闻来源:</td><td><input type="text" name="source"></td></tr>
                <tr><td>新闻类型:</td><td><input type="text" name="type"></td></tr>
                <tr><td>阅读量:</td><td><input type="text" name="quantity"></td></tr>
                <tr><td colspan="2" align="center"><input type="submit" name="submit" value="添加">
                    <input type="reset" name="reset" value="重置"></td></tr>
            </table>
        </form>
    </center>
    </body>
</html>

删除新闻delnews.jsp

<%@ page language="java" contentType="text/html; charset=GBK"
    pageEncoding="GBK"%>
<%@page import="java.sql.*" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GBK">
<title>新闻信息删除</title>
</head>
 <body bgcolor="yellow">
        <%=session.getAttribute("username") %>同学,您好!欢迎来到新闻发布系统!
    <center>
        <h1>新闻发布系统-删除新闻信息</h1>
        <%@include file="header.jsp" %>
        <hr>
        <%
           request.setCharacterEncoding("GBK");
           Class.forName("com.mysql.jdbc.Driver");
           Connection conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/news", "root", "111111");
           Statement stmt=conn.createStatement();
           String sql="select * from newsinfo";
           ResultSet rs=stmt.executeQuery(sql);
        %>
        <table border="1">
            <tr><th>新闻标题</th><th>作者</th><th>发布时间</th><th>新闻来源</th><th>新闻类型</th><th>阅读量</th><th>管理</th></tr>
            <%
            while(rs.next()){
                int id=rs.getInt("id");
            %>
           <tr><td><%=rs.getString("name") %></td>
            <td><%=rs.getString("author") %></td>
            <td><%=rs.getDate("time") %></td>
            <td><%=rs.getString("source") %></td>
            <td><%=rs.getString("type") %></td>
            <td><%=rs.getInt("quantity") %></td>
            <td><a href='del.do?id=<%=id%>' onclick="return confirm('确定要删除该新闻s吗?')">删除</a></td>
            </tr>
           <%}%>
           <tr><td colspan="7" align="center"><input type="button" name="bn" value="返回首页" onclick="javascript:location.href='index.jsp'"></td></tr>
        </table>
    </center>
    </body>
</html>

新闻修改页面ediit.jsp,editnews.jsp

<%@ page language="java" contentType="text/html; charset=GBK"
    pageEncoding="GBK"%>
<%@page import="news.NewsInfo"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GBK">
<title>修改新闻信息</title>
</head>
 <body bgcolor="yellow">
        <%=session.getAttribute("username") %>您好!欢迎来到新闻发布系统!
    <center>
        <h1>新闻信息修改</h1>
        <%@include file="header.jsp" %>
        <hr>
        <% NewsInfo bi=(NewsInfo)request.getAttribute("bi"); %>
        <form action="update.do" method="post">
            <input type="hidden" name="id" value="<%=bi.getId() %>">
            <table border="1">
                <tr><td>新闻标题:</td><td><input type="text" name="name" value="<%=bi.getName() %>"></td></tr>
                <tr><td>作者:</td><td><input type="text" name="author" value="<%=bi.getAuthor() %>"></td></tr>
                <tr><td>发布时间:</td><td><input type="text" name="time" value="<%=bi.getTime() %>"></td></tr>
                <tr><td>新闻来源:</td><td><input type="text" name="source" value="<%=bi.getSource() %>"></td></tr>
                <tr><td>新闻类型:</td><td><input type="text" name="type" value="<%=bi.getType() %>"></td></tr>
                <tr><td>阅读量:</td><td><input type="text" name="quantity" value="<%=bi.getQuantity() %>"></td></tr>
                <tr><td colspan="2" align="center"><input type="submit" name="submit" value="修改">
                    <input type="reset" name="reset" value="重置"></td></tr>
            </table>
        </form>
    </center>
    </body>
</html>
<%@ page language="java" contentType="text/html; charset=GBK"
    pageEncoding="GBK"%>
<%@page import="java.sql.*" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GBK">
<title>新闻修改</title>
</head>
<body bgcolor="yellow">
        <%=session.getAttribute("username") %>同学,您好!欢迎来到新闻发布系统!
    <center>
        <h1>新闻发布系统-选择新闻信息</h1>
        <%@include file="header.jsp" %>
        <hr>
        <%
           request.setCharacterEncoding("GBK");
           Class.forName("com.mysql.jdbc.Driver");
           Connection conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/news", "root", "111111");
           Statement stmt=conn.createStatement();
           String sql="select * from newsinfo";
           ResultSet rs=stmt.executeQuery(sql);
        %>
        <table border="1">
            <tr><th>新闻标题</th><th>作者</th><th>发布时间</th><th>新闻来源</th><th>新闻类型</th><th>阅读量</th><th>管理</th></tr>
            <%
            while(rs.next()){
                int id=rs.getInt("id");
            %>
           <tr><td><%=rs.getString("name") %></td>
            <td><%=rs.getString("author") %></td>
            <td><%=rs.getDate("time") %></td>
            <td><%=rs.getString("source") %></td>
            <td><%=rs.getString("type") %></td>
            <td><%=rs.getInt("quantity") %></td>
            <td><a href='edit.do?id=<%=id%>'>修改</a></td>
            </tr>
           <%}%>
           <tr><td colspan="7" align="center"><input type="button" name="bn" value="返回首页" onclick="javascript:location.href='index.jsp'"></td></tr>
        </table>
    </center>
    </body>
</html>

操作失败页面failure.jsp,成功页面success.jsp

<%@ page language="java" contentType="text/html; charset=GBK"
    pageEncoding="GBK"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GBK">
<title>操作提示页面</title>
</head>
<body bgcolor="yellow">
    <center>
        <h1>新闻发布系统</h1>
        <%@include file="header.jsp" %>
        <hr>
        <font face="黑体" size="5" color="blue">操作失败!</font>
    </center>
    </body>
</html>
<%@ page language="java" contentType="text/html; charset=GBK"
    pageEncoding="GBK"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GBK">
<title>操作提示页面</title>
</head>
<body bgcolor="yellow">
    <center>
        <h1>新闻发布系统</h1>
        <%@include file="header.jsp" %>
        <hr>
        <font face="黑体" size="5" color="blue">修改成功,点击<a href="index.jsp ">返回</a>首页!</font>
    </center>
    </body>
</html>

头部页面header.jsp

<%@ page language="java" contentType="text/html; charset=GBK"
    pageEncoding="GBK"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GBK">
<title>头部</title>
</head>
<body bgcolor="yellow">
    <center>
        <div>
            <a href="addnews.jsp">新闻信息添加</a> <a href="list.jsp">新闻信息显示</a> 
            <a href="editnews.jsp">新闻信息修改</a> 
            <a href="delnews.jsp">新闻信息删除</a> <a href="password.jsp">密码修改</a> 
            <a href="logout.jsp">退出登录</a>
        </div>
    </center>
</body>
</html>

首页index.jsp

<%@ page language="java" contentType="text/html; charset=GBK"
    pageEncoding="GBK"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GBK">
<title>首页</title>
</head>
<body bgcolor="yellow">
    <center>
        <h1>新闻发布系统首页</h1>
        <%@include file="header.jsp" %>
        <hr>
        <font face="隶书" size="5" color="blue"><%=session.getAttribute("username")%>同学,您好!欢迎您来到新闻发布系统!</font>
    </center>
    </body>
</html>

信息显示页面list.jsp

<%@ page language="java" contentType="text/html; charset=GBK"
    pageEncoding="GBK"%>
<%@page import="java.util.*,news.NewsInfo"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GBK">
<title>新闻信息显示</title>
</head>
<body bgcolor="yellow">
        <%=session.getAttribute("username") %>同学,您好!欢迎来新闻发布系统!
    <center>
        <h1>新闻发布系统-新闻信息显示</h1>
        <%@include file="header.jsp" %>
        <hr>
        <table border="1">
            <tr><th>新闻标题</th><th>作者</th><th>发布时间</th><th>新闻来源</th><th>新闻类型</th><th>阅读量</th></tr>
            <%
           NewsInfo ni = new NewsInfo();
            ArrayList<NewsInfo> list=new ArrayList<NewsInfo>();
			 //list=(ArrayList<NewsInfo>)request.getAttribute("list");
			 list = ni.getNewsList();
            for(int i=0;i<list.size();i++){
                
            %>
            <tr>
                <td><%=list.get(i).getName() %></td>
                <td><%=list.get(i).getAuthor() %></td>
                <td><%=list.get(i).getTime() %></td>
                <td><%=list.get(i).getSource() %></td>
                <td><%=list.get(i).getType() %></td>
                <td><%=list.get(i).getQuantity() %></td>
            </tr>
            <%}%>
            <tr><td colspan="6" align="center"><input type="button" name="bn" value="返回首页" onclick="javascript:location.href='index.jsp'"></td></tr>
        </table>
    </center>
    </body>
</html>

登入失败页面logFailure.jsp

<%@ page language="java" contentType="text/html; charset=GBK"
    pageEncoding="GBK"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GBK">
<title>登录失败</title>
</head>
<body bgcolor="yellow">
    <center>
        <h1>登录失败</h1>
        <hr>
        <p><font face="黑体" size="5" color="blue">用户名或密码错误,5秒钟后<a href=" ">返回</a>登陆页面</font></p >
        <%
            response.setHeader("refresh", "5;url=login.jsp");
        %>
    </center>
    </body>
</html>

登入页面login.jsp

<%@ page language="java" contentType="text/html; charset=GBK"
    pageEncoding="GBK"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GBK">
<title>新闻发布系统-用户登录</title>
</head>
 <body bgcolor="yellow">
        <center>
        <h1>新闻发布系统-用户登录</h1>
        <hr>
        <form action="login.do" method="post">
            <table border="1">
                <tr><th>用户名</th><td><input type="text" name="username"></td></tr>
                <tr><th>密码</th><td><input type="password" name="pwd"></td></tr>
                <tr><td colspan="2" align="center">
                        <input type="submit" name="submit" value="登录">
                        <input type="reset" name="reset" value="重置">
                        <input type="button" name="bn" value="新用户注册" onclick="javascript:location.href='register.jsp'"></td></tr>
            </table>
        </form>
    </center>
    </body>
</html>

退出系统页面logout.jsp

<%@ page language="java" contentType="text/html; charset=GBK"
    pageEncoding="GBK"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GBK">
<title>退出登录</title>
</head>
<body bgcolor="yellow">
        <%=session.getAttribute("username") %>同学,您好!欢迎来到新闻发布系统!
    <center>
        <h1>新闻发布系统-退出登录</h1>
        <%@include file="header.jsp" %>
        <hr>
        <%
            request.setCharacterEncoding("GBK");
            session.invalidate();
        %>
        <font face="隶书" size="5" color="blue">正在退出登录,5秒钟后<a href=" login.jsp">返回</a>登陆页面</font>
        <%
            out.println("<script language=javascript> alert('退出成功,点击确定返回首页!');</script>");
            response.setHeader("refresh", "5;url=login.jsp");
        %>
    </center>
    </body>
</html>

密码修改password.jsp

<%@ page language="java" contentType="text/html; charset=GBK"
    pageEncoding="GBK"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GBK">
<title>密码修改</title>
</head>
<body bgcolor="yellow">
        <%=session.getAttribute("username") %>同学,您好!欢迎来到新闻发布系统!
    <center>
        <h1>新闻发布系统-密码修改</h1>
        <%@include file="header.jsp" %>
        <hr>
        <form action="password.do" method="post">
            <p><%=session.getAttribute("username") %>同学,您好,请输入您的新密码: <input type="password" name="pwd">
                <input type="submit" name="submit" value="密码修改"></p >
        </form>
    </center>
    </body>
</html>

注册失败regFailure.jsp

<%@ page language="java" contentType="text/html; charset=GBK"
    pageEncoding="GBK"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GBK">
<title>注册失败</title>
</head>
<body bgcolor="yellow">
    <center>
        <div><font face="黑体" color="blue" size="5">用户注册失败,点击<a href=" ">返回</a>重新注册!</font></div>
    </center>
    </body>
</html>

注册页面register.jsp

<%@ page language="java" contentType="text/html; charset=GBK"
    pageEncoding="GBK"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GBK">
<script>
    function checkName() {
        var username = f.username.value;
        if (username == "") {
            alert("请输入用户名")
        } else {
            window.open("checkName.do?username=" + encodeURI(username));
        }
    }
    function check() {
        if (f.username.value == "") {
            alert("用户名不能为空!");
            f.username.focus();
            return false;
        }
        if (f.pwd.value != f.compwd.value) {
            alert("两次密码不一致!");
            f.pwd.focus();
            return false;
        }
        if (document.f.email.value.indexOf("@", 0) == -1
                || document.f2.email.value.indexOf(".", 0) == -1) {
            window.alert("Email的格式不正确!");
            document.f.email.focus();
            return false;
        }

        return true;
    }
</script>
<title>用户注册</title>
</head>
<body bgcolor="yellow">
    <center>
        <h1>新闻发布系统-用户注册</h1>
        <hr>
        <form action="register.do"method="post">
            <table border="1">
                <tr><td colspan="3" align="center">请输入您的注册信息</td></tr>
                <tr><td>用户名</td><td><input type="text" name="username"></td><td>
                <tr><td>密码</td><td><input type="password" name="pwd"></td></tr>
                <tr><td>确认密码</td><td><input type="password" name="compwd"></td></tr>
                <tr><td>性别</td><td><input type="radio" name="sex" value="1">男
                    <input type="radio" name="sex" value="0">女</td></tr>
                <tr><td>Email地址</td><td><input type="text" name="email"></td></tr>
                <tr><td colspan="3" align="center"><input type="submit" name="submit" value="注册">
                    <input type="reset" name="reset" value="重置"></td></tr>
            </table>
        </form>
    </center>
    </body>
</html>

注册成功regSuccess.jsp

<%@ page language="java" contentType="text/html; charset=GBK"
    pageEncoding="GBK"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GBK">
<title>注册成功</title>
</head>
<body bgcolor="yellow">
    <center>
        <div><font face="黑体" color="blue" size="5">用户注册成功,点击<a href="login.jsp">返回</a>登陆页面!</font></div>
    </center>
    </body>
</html>

用户是否存在userExit.html,userUnexit.html

<!DOCTYPE html>
<html>
<head>
<meta charset="GBK">
<title>用户名已存在</title>
</head>
<body bgcolor="yellow">
     <div><font face="黑体" color="blue" size="5">用户名已存在,请重新选择!</font></div>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<meta charset="GBK">
<title>用户名不存在</title>
</head>
<body bgcolor="yellow">
    <div><font face="黑体" color="blue" size="5">用户名可用!</font></div>
</body>
</html>

其中查找用户名和搜索的功能删掉了。

各位大佬可提提意见。

  • 4
    点赞
  • 26
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值