MVC框架的简介
主流框架是MVC框架技术
- 1:jsp+servlet+javabean适用于较小的项目
- 2:Struts+Spring+Hibernate
目前这是主流框架技术组合在一起就是SSH了 , 适用于要求可维护性强的框架技术
- Struts主要负责表示层的显示
- Spring利用它的IOC和APO来处理控制业务(负责对数据库的操作)
- Hibernate主要是数据持久化到数据库
- 再用jsp的servlet做网页开发的时候有个wed.xml的映射文件 , 里面有个mapping的标签就是用来做文件映射的 . 当你在浏览器上输入URL得知的时候 , 文件就会根据你写的名称对应到一个JAVA文件 , 根据java文件里编写的内容显示在浏览器上, 就是一个网页 .
三大框架的简介
Struts框架
struts是开源软件 . 使用struts而目的是为了帮助我们减少在运用MVC设计模型来开发Web应用的时间. 如果我们想混合使用Servlets和JSP的优点来建立可扩展的应用 , struts是一个不错的选择.
1 . 流程 : 服务器启动后 , 根据web.xml加载ActionServlet读取struts-config.xml文件内容到内存 .
2 . 架构 : Struts对Model , View和Controller都提供了对应的组件 . ActionServlet , 这个类是Struts的核心控制器 , 负责拦截来自用户的请求 .
3 . Model部分 : 由JavaBean组成 , ActionForm用于封装用户的请求参数,封装成ActionForm对象 , 该对象被ActionServlet转发给Action , Action根据ActionFrom里面的请求参数处理用户的请求 . JavaBean则封装了底层的业务逻辑 , 包括数据库访问等 .
4 . View部分 : 该部分采用JSP实现 . Struts提供了丰富的标签库 , 通过标签库可以减少脚本的使用 , 自定义的标签库可以实现与Model的有效交互, 并增加了现实功能 .
5 . Controller组件 : Controller组件有两个部分组成——系统核心控制器 , 业务逻辑控制器 . 系统核心控制器 , 该控制器由Struts框架提供 , 继承HttpServlet类 , 因此可以配置成标注的Servlet . 该控制器负责拦截所有的HTTP请求 , 然后根据用户请求决定是否要转给业务逻辑控制器 . 业务逻辑控制器 , 负责处理用户请求 , 本身不具备处理能力 , 而是调用Model来完成处理 . 对应Action部分.
Spring框架
Spring是一个解决了许多在J2EE开发中常见的的问题的强大框架 . Springle提供了管理业务对象的一致方法并且鼓励了注入对接口编程而不是对类变成的好习惯 . Spring的架构基础是基于使用JavaBean属性的Inversion of Control 容器 . 然而Spring在使用IoC容器作为构建玩关注所有架构层层的完整解决方案方面是独一无二的 . Spring提供了唯一的数据管理抽象包括简单和有效率的JDBC框架 , 极大的改进了效率并且减少了可能的错误 . Spring的数据访问架构还集成了Hibernate和其他O/R mapping 解决方案 .
Hiernate框架
Hibernate 是一个开源代码的对象关系映射框架 , 对JDBC惊醒了费城轻量级的的对象封装 , 使得Java程序员可以随心所欲的使用对象变成思维来操作数据库 . Hebernate可以应用在任何使用JDBC的场合 , 既可以在java的客户端程序使用 , 也可以在Servlet/JSP的Web应用中使用最具革命意义的事, Hibernate可以在应用EJB的J2EE架构中取代CMP , 完成数据持久化的重任 .
Hibernate的核心接口一共有5个 , 分别为:Session、SessionFactory、Transaction、Query和Configuration . 这5个核心接口在任何开发中都会用到 . 通过这些接口 , 不仅可以对持久化对象进行存取 , 还能够进行事务控制 . 下面对这五个核心接口分别加以介绍.
1.Session接口 : 负责执行被持久化对象的CRUD操作(CRUD的任务是完成与数据库的交流 , 包含了很多常见的SQL语句 . ) . 但需要注意的是Session对象是非线程安全的. 同时, Hibernate的session不同于JSP应用中的HttpSession . 这里当使用session这个术语时 , 其实指的是Hibernate中的session,而以后会将HttpSession对象称为用户session .
2.SessionFactory接口:负责初始化Hibernate . 它充当数据存储源的代理 , 并负责创建Session对象 . 这里用到了工厂模式 . 需要注意的是SessionFactory并不是轻量级的 , 因为一般情况下 , 一个项目通常只需要一个SessionFactory就够 , 当需要操作多个数据库时 , 可以为每个数据库指定一个SessionFactory .
3.Configuration接口:负责配置并启动Hibernate , 创建SessionFactory对象 . 在Hibernate的启动的过程中 , Configuration类的实例首先定位映射文档位置、读取配置,然后创建SessionFactory对象 .
4.Transaction接口:负责事务相关的操作 . 它是可选的 , 开发人员也可以设计编写自己的底层事务处理代码 .
5.Query和Criteria接口:负责执行各种数据库查询 . 它可以使用HQL语言或SQL语句两种表达方式 .
新闻信息管理系统的结构
源包
- 数据库的连接 DBConnection.java
- 新闻信息 NewsInfo.java
- 用户信息 UserInfo.java
- 控制器 newsController.javaWebContent
- 创建表 createTable.java
- 用户登录页面 login.jsp
- 用户注册页面 register.jsp
- 操作成功提示页面 success.jsp
- 操作失败提示页面 failure.jsp
- 登录失败页面 logFailure.jsp
- 注册成功页面 regSuccess.jsp
- 注册失败页面 regFailure.jsp
- 注册时提示用户名是否已存在页面 userExist.html userUnexist.html
- 系统首页 index.jsp
- 系统头部页面 header.jsp
- 系统版权页 copyreght.jsp
- 信息添加页面 addnews.jsp
- 信息显示页面 list.jsp
- 信息修改页面 ediit.jsp editnews.jsp
- 信息查询页面 searchnews.jsp (简单查询) advsearch.jsp (高级查询)
- 信息删除页面 delnews.jsp
- 用户密码修改页面 password.jsp
- 退出系统页面 logout.jsp
代码演示
- 数据库的连接 DBConnection.java
package com.NewsMVC;
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="4444";
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("数据库关闭失败");}
}
}
package com.NewsMVC;
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 getNewsList(){
ArrayList list=new ArrayList();//使用list存储火车记录
String sql="select * from newsinfo";
DBConnection db=new DBConnection();
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();//实例化TrainInfo类bi,用来存放通过id获取的新闻信息
try{
if(rs.next()){
bi.setId(rs.getString("id"));
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"));
}
}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 static ArrayList getSearchList(String name){
ArrayList list=new ArrayList();//使用list存储新闻记录
String sql="select * from newsinfo where name like '%"+name+"%'";
DBConnection db=new DBConnection();
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;
}
//新闻信息高级搜索
public static ArrayList getAdvSearchList(String name,String author){
ArrayList list=new ArrayList();//使用list存储新闻记录
String sql="select * from newsinfo where name like '%"+name+"%' and author like '%"+author+"%'";
DBConnection db=new DBConnection();
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;
}
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;
}
}
package com.NewsMVC;
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;
}
}
package com.NewsMVC;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/** * 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 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("/edit.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);
} else if (actionUrl.equals("/search.do")) {// 当获得的地址为简单搜索search.do
String name = request.getParameter("name");
ArrayList list = NewsInfo.getSearchList(name);
request.setAttribute("list", list);
request.getRequestDispatcher("/list.jsp").forward(request, response);
} else if (actionUrl.equals("/advsearch.do")) {
String name = request.getParameter("name");
String author = request.getParameter("author");
ArrayList list = NewsInfo.getAdvSearchList(name, author);
request.setAttribute("list", list);
request.getRequestDispatcher("/list.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);
}
}
<%@ page language="java" contentType="text/html; charset=GBK" pageEncoding="GBK"%>
<%@page import="java.sql.*" %>
<jsp:useBean id="db" class="com.NewsMVC.DBConnection" scope="page"/>
<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(""); response.setHeader("refresh", "1;url=login.jsp"); } %>
center>
body>
html>
<%@ page language="java" contentType="text/html; charset=GBK" pageEncoding="GBK"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GBK">
<title>新闻信息管理系统-用户登录title>
head>
<body bgcolor="#ffddee">
<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>
<%@include file="copyright.jsp" %>
body>
html>
<%@ page language="java" contentType="text/html; charset=GBK" pageEncoding="GBK"%>
<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="#ffddee">
<center>
<h1>新闻信息管理系统-用户注册h1>
<hr>
<form method="post" name="f" action="register.do" onSubmit="return check()">
<table border="1">
<tr><td colspan="3" align="center">请输入您的注册信息td>tr>
<tr><td>用户名td><td><input type="text" name="username">td><td><a href="javascript:checkName()">检查用户名是否可用a>td>tr>
<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>
<%@ page language="java" contentType="text/html; charset=GBK" pageEncoding="GBK"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GBK">
<title>操作提示页面title>
head>
<body bgcolor="#ffddee">
<center>
<h1>新闻信息管理系统h1>
<%@include file="header.jsp" %>
<hr>
<font face="黑体" size="5" color="blue">修改成功,点击<a href="index.jsp">返回a>首页!font>
center>
<%@include file="copyright.jsp" %>
body>
html>
<%@ page language="java" contentType="text/html; charset=GBK" pageEncoding="GBK"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GBK">
<title>操作提示页面title>
head>
<body bgcolor="#ffddee">
<center>
<h1>新闻信息管理系统h1>
<%@include file="header.jsp" %>
<hr>
<font face="黑体" size="5" color="blue">操作失败!font>
center>
<%@include file="copyright.jsp" %>
body>
html>
<%@ page language="java" contentType="text/html; charset=GBK" pageEncoding="GBK"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GBK">
<title>登录失败title>
head>
<body bgcolor="#ffddee">
<center>
<h1>登录失败h1>
<hr>
<p><font face="黑体" size="5" color="blue">用户名或密码错误,5秒钟后<a href="login.jsp">返回a>登陆页面font>p>
<% response.setHeader("refresh", "5;url=login.jsp"); %>
center>
<%@include file="copyright.jsp" %>
body>
html>
<%@ page language="java" contentType="text/html; charset=GBK" pageEncoding="GBK"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GBK">
<title>注册成功title>
head>
<body bgcolor="#ffddee">
<center>
<div><font face="黑体" color="blue" size="5">用户注册成功,点击<a href="login.jsp">返回a>登陆页面!font>div>
center>
<%@include file="copyright.jsp" %>
body>
html>
<%@ page language="java" contentType="text/html; charset=GBK" pageEncoding="GBK"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GBK">
<title>注册失败title>
head>
<body bgcolor="#ffddee">
<center>
<div><font face="黑体" color="blue" size="5">用户注册失败,点击<a href="register.jsp">返回a>重新注册!font>div>
center>
<%@include file="copyright.jsp" %>
body>
html>
<html>
<head>
<meta charset="GBK">
<title>用户名已存在title>
head>
<body bgcolor="#ffddee">
<center>
<div><font face="黑体" color="blue" size="5">用户名已存在,请重新选择!font>div>
center>
body>
html>
<html>
<head>
<meta charset="GBK">
<title>用户名不存在title>
head>
<body bgcolor="#ffddee">
<center>
<div><font face="黑体" color="blue" size="5">用户名可用!font>div>
center>
body>
html>
<%@ page language="java" contentType="text/html; charset=GBK" pageEncoding="GBK"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GBK">
<title>首页title>
head>
<body bgcolor="#ffddee">
<center>
<h1>新闻信息管理系统首页h1>
<%@include file="header.jsp" %>
<hr>
<font face="隶书" size="5" color="blue"><%=session.getAttribute("username") %>,您好!欢迎您来到中华新闻网,本系统是由学生在实训课时使用MVC模式设计和开发完成的,若有不足之处,请指正,谢谢!font>
<%@include file="copyright.jsp" %>
center>
body>
html>
<%@ page language="java" contentType="text/html; charset=GBK" pageEncoding="GBK"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GBK">
<title>头部title>
head>
<body bgcolor="#ffddee">
<center>
<div>
<a href="addnews.jsp">新闻信息添加a> <a href="list.do">新闻信息显示a> <a href="editnews.jsp">新闻信息修改a> <a href="searchnews.jsp">新闻信息查询a> <a href="delnews.jsp">新闻信息删除a> <a href="password.jsp">密码修改a> <a href="logout.jsp">退出登录a>
div>
center>
body>
html>
<%@ page language="java" contentType="text/html; charset=GBK" pageEncoding="GBK"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GBK">
<title>版权页title>
head>
<body bgcolor="#ffddee">
<center>
<div style="position: fixed;bottom: 0px;width: 100%;text-align: center">
<font face="隶书" size="5" color="red">copyright © 中华新闻网版权所有font>
div>
center>
body>
html>
<%@ page language="java" contentType="text/html; charset=GBK" pageEncoding="GBK"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GBK">
<title>新闻信息管理系统-新闻信息入库title>
head>
<body bgcolor="#ffddee">
<%=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>
<%@include file="copyright.jsp" %>
body>
html>
<%@ page language="java" contentType="text/html; charset=GBK" pageEncoding="GBK"%>
<%@page import="java.util.*,com.NewsMVC.NewsInfo"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GBK">
<title>新闻信息显示title>
head>
<body bgcolor="#ffddee">
<%=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>
<% ArrayList list=(ArrayList)request.getAttribute("list"); for(NewsInfo bi:list){ String id=bi.getId(); %>
<tr>
<td><%=bi.getName() %>td>
<td><%=bi.getAuthor() %>td>
<td><%=bi.getTime() %>td>
<td><%=bi.getSource() %>td>
<td><%=bi.getType() %>td>
<td><%=bi.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>
<%@include file="copyright.jsp" %>
body>
html>
<%@ page language="java" contentType="text/html; charset=GBK" pageEncoding="GBK"%>
<%@page import="com.NewsMVC.NewsInfo"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GBK">
<title>修改新闻信息title>
head>
<body bgcolor="#ffddee">
<%=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>
<%@include file="copyright.jsp" %>
body>
html>
<%@ page language="java" contentType="text/html; charset=GBK" pageEncoding="GBK"%>
<%@page import="java.sql.*" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GBK">
<title>新闻修改title>
head>
<body bgcolor="#ffddee">
<%=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", "4444"); 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>
<%@include file="copyright.jsp" %>
body>
html>
<%@ page language="java" contentType="text/html; charset=GBK" pageEncoding="GBK"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GBK">
<title>简单搜索title>
head>
<body bgcolor="#ffddee">
<%=session.getAttribute("username") %>,您好!欢迎来到中华新闻网!
<center>
<h1>新闻信息管理系统-简单搜索h1>
<%@include file="header.jsp" %>
<hr>
<form action="search.do" method="post">
<p>请输入您要搜索的新闻标题:<input type="text" name="name">
<input type="submit" name="submit" value="简单搜索">
<input type="button" name="bn" value="高级搜索" onclick="javascript:location.href='advsearch.jsp'">
p>
form>
center>
<%@include file="copyright.jsp" %>
body>
html>
<%@ page language="java" contentType="text/html; charset=GBK" pageEncoding="GBK"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GBK">
<title>高级搜索title>
head>
<body bgcolor="#ffddee">
<%=session.getAttribute("username") %>,您好!欢迎来到中华新闻网!
<center>
<h1>新闻信息管理系统-高级搜索h1>
<%@include file="header.jsp" %>
<hr>
<form action="advsearch.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 colspan="2" align="center"><input type="submit" name="submit" value="高级搜索">
<input type="reset" name="reset" value="重置">td>tr>
table>
form>
center>
<%@include file="copyright.jsp" %>
body>
html>
<%@ page language="java" contentType="text/html; charset=GBK" pageEncoding="GBK"%>
<%@page import="java.sql.*" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GBK">
<title>新闻信息删除title>
head>
<body bgcolor="#ffddee">
<%=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", "4444"); 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>
<%@include file="copyright.jsp" %>
body>
html>
<%@ page language="java" contentType="text/html; charset=GBK" pageEncoding="GBK"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GBK">
<title>密码修改title>
head>
<body bgcolor="#ffddee">
<%=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>
<%@include file="copyright.jsp" %>
body>
html>
<%@ page language="java" contentType="text/html; charset=GBK" pageEncoding="GBK"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GBK">
<title>退出登录title>
head>
<body bgcolor="#ffddee">
<%=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(""); response.setHeader("refresh", "5;url=login.jsp"); %>
center>
<%@include file="copyright.jsp" %>
body>
html>