河北省环保建设新闻报告系统(下)

writer login.jsp

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>登录</title>
</head>
<body>
<form action="Writer_Login_back.jsp" method="get">
<p style="text-align:center;color: black; font-family: 宋体; font-size: 20px">
新闻撰稿人登录
<br>
工号
<input type="text" name="WriterID" >
<br>
密码
<input type="text" name="Wpassword" >
<br>
<input type="submit" value="登录" >
</p>
</form>
</body>
</html>

login back.jsp

<%@ page import="java.sql.Connection" %>
<%@ page import="java.sql.PreparedStatement" %>
<%@ page import="com.Util.util" %>
<%@ page import="java.sql.ResultSet" %>
<%@ page import="java.sql.SQLException" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title></title>
</head>
<body>
<%
String WriterID=(String)request.getParameter("WriterID");

session.setAttribute("WriterID",WriterID);

String Wpassword=(String)request.getParameter("Wpassword");

session.setAttribute("Wpassword",Wpassword);

if(WriterID==""||Wpassword=="")
{
out.print("<script language='javaScript'> alert('工号或密码输入为空'); window.history.back(); </script>");
}
else
{

int i=0;
Connection connection = util.getConnection();
PreparedStatement preparedStatement=null;
ResultSet rs=null;
try {
String sql= " select * from Writer ";
preparedStatement=connection.prepareStatement(sql);
rs=preparedStatement.executeQuery();
while(rs.next())
{
if(WriterID.equals(rs.getObject(1))&&Wpassword.equals(rs.getObject(2)))
{i++;}
}
if(i==0)
{
out.print("<script language='javaScript'> alert('工号或密码错误'); window.history.back(); </script>");
}
else
{
out.print("<script language='javaScript'> alert('登录成功');</script>");
response.setHeader("refresh", "0;url=Writer_Menu.jsp");
}
} catch (SQLException e) {
e.printStackTrace();
}finally{
util.close(rs);
util.close(preparedStatement);
util.close(connection);
}
}
%>

</table>
</body>
</html>

menu.jsp

<%@ page language= "java" contentType= "text/html; charset=UTF-8"
pageEncoding= "UTF-8" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta charset="UTF-8">
<h1 align = "center">新闻撰稿人系统</h1><br>
</head>
<body>
<div align = "center"> <a href="Writer_write.jsp">在线撰写</button ></a></div><br>
<div align = "center"> <a href="Writer_Update.jsp">修改稿件</button></a></div><br>
<div align = "center"> <a href="Writer_Chazhao.jsp">查看稿件</button></a></div><br>
<div align = "center"> <a href="Writer_Advice.jsp">查看修改意见</button></a></div><br>
</body>
</html>

update.jsp

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>新闻撰写</title>
</head>
<body>
<form action="update?method=update" method="get">
<h1 align = "center"><tr><td>新闻修改</td></tr></h1>
<table align="center">
<tr>
<td>需要修改的新闻主题:</td>
<td>
<input type="text" name="name0" maxlength="20" style="width:500px;">
</td>
</tr>
<tr>
<td>新闻主题:</td>
<td>
<input type="text" name="name" maxlength="20" style="width:500px;">
</td>
</tr>
<tr>
<td> 新闻作者:</td>
<td>
<input type="text" name="writer" maxlength="50" style="width:500px;">
</td>
</tr>
<tr>
<td>关键字:</td>
<td>
<input type="text" name="type" >
</td>
</tr>
<tr>
<td>发生时间:</td>
<td>
<input type="text" name="time">
</td>
</tr>
<tr>
<td>新闻内容:</td>
<td>
<input type="text" name="neirong" maxlength="500" style="height:100px;width:500px;">
</td>
</tr>
</p>
<tr>
<td colspan="2"><div align="center">
<input type="submit" value="修改">
</div>
</td>
</tr>
</form>
</body>
</html>

write.jsp

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>新闻撰写</title>
</head>
<body>
<form action="Writer_write_back.jsp" method="get">
<h1 align = "center"><tr><td>新闻撰写</td></tr></h1>
<table align="center">
<tr>
<td>新闻主题:</td>
<td>
<input type="text" name="name" maxlength="20" style="width:500px;">
</td>
</tr>
<tr>
<td> 新闻作者:</td>
<td>
<input type="text" name="writer" maxlength="50" style="width:500px;">
</td>
</tr>
<tr>
<td>关键字:</td>
<td>
<input type="text" name="type" >
</td>
</tr>
<tr>
<td>发生时间:</td>
<td>
<input type="text" name="time">
</td>
</tr>
<tr>
<td>新闻内容:</td>
<td>
<input type="text" name="neirong" maxlength="500" style="height:100px;width:500px;">
</td>
</tr>
</p>
<tr>
<td colspan="2"><div align="center">
<input type="submit" value="录入">
</div>
</td>
</tr>
</form>
</body>
</html>

write_back.jsp

<%@ page import="com.Bean.bean" %>
<%@ page import="com.Dao.dao" %>
<%@ page language= "java" import="java.util.*" contentType= "text/html; charset=UTF-8"
pageEncoding= "UTF-8" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<meta charset="UTF-8">

<%
String name=request.getParameter("name");
String writer=request.getParameter("writer");
String type=request.getParameter("type");
String time=request.getParameter("time");
String neirong=request.getParameter("neirong");
if(name=="")
{
out.print("<script language='javaScript'> alert('某项输入为空'); window.history.back(); </script>");
}
else
{
bean bean = new bean();
bean.setName(name);
bean.setWriter(writer);
bean.setType(type);
bean.setTime(time);
bean.setNeirong(neirong);
dao dao = new dao();
dao.AddNews(bean);
out.print("<script language='javaScript'> alert('添加成功');</script>");
response.setHeader("refresh", "0;url=Writer_Menu.jsp");
}
%>
</html>

 

bean.java

package com.Bean;

public class bean {
public String name;
public String writer;
public String type;
public String time;
public String neirong;
public String UserID;
public String Upassword;
public String getUserID() {
return UserID;
}
public void setUserID(String userID) {
UserID = userID;
}
public String getUpassword() {
return Upassword;
}
public void setUpassword(String upassword) {
Upassword = upassword;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getWriter() {
return writer;
}
public void setWriter(String writer) {
this.writer = writer;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getTime() {
return time;
}
public void setTime(String time) {
this.time = time;
}
public String getNeirong() {
return neirong;
}
public void setNeirong(String neirong) {
this.neirong = neirong;
}
}

Dao.java

package com.Dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

import com.Bean.bean;
import com.Util.util;


import com.Bean.bean;
import com.Util.util;

public class dao {
public void AddNews(bean bean)
{
Connection connection= util.getConnection();
PreparedStatement preparedStatement=null;
try
{
String sql="insert into news(name,writer,type,time,neirong) values(?,?,?,?,?)";
preparedStatement =connection.prepareStatement(sql);
preparedStatement.setString(1,bean.getName());
preparedStatement.setString(2,bean.getWriter());
preparedStatement.setString(3,bean.getType());
preparedStatement.setString(4,bean.getTime());
preparedStatement.setString(5,bean.getNeirong());
preparedStatement.executeUpdate();
}
catch (SQLException e)
{
e.printStackTrace();
}
finally
{
util.close(preparedStatement);
util.close(connection);
}
}
public void Adduser(bean bean)
{
Connection connection= util.getConnection();
PreparedStatement preparedStatement=null;
try
{
String sql="insert into abc(UserID,Upassword) values(?,?)";
preparedStatement =connection.prepareStatement(sql);
preparedStatement.setString(1,bean.getUserID());
preparedStatement.setString(2,bean.getUpassword());
preparedStatement.executeUpdate();
}
catch (SQLException e)
{
e.printStackTrace();
}
finally
{
util.close(preparedStatement);
util.close(connection);
}
}
public void CheckNews(String test,String name)
{
Connection connection =util.getConnection();
PreparedStatement preparedStatement=null;
try {
String sql = "update news set test=? where name=?";
preparedStatement=connection.prepareStatement(sql);
preparedStatement.setString(1,test);
preparedStatement.setString(2,name);
preparedStatement.executeUpdate();

} catch (SQLException e) {
e.printStackTrace();
}finally{
util.close(preparedStatement);
util.close(connection);
}
}
public void ChangeUserPassword(String Upassword,String UserID)
{
Connection connection =util.getConnection();
PreparedStatement preparedStatement=null;
try {
String sql = "update abc set Upassword=?where UserID=?";
preparedStatement=connection.prepareStatement(sql);
preparedStatement.setString(1,Upassword);
preparedStatement.setString(2,UserID);
preparedStatement.executeUpdate();

} catch (SQLException e) {
e.printStackTrace();
}finally{
util.close(preparedStatement);
util.close(connection);
}
}
}

 

util.java

package com.Util;

import java.sql.*;

public class util
{
public static Connection getConnection()//连接数据库
{
try{
Class.forName("com.mysql.cj.jdbc.Driver");
//System.out.println("加载驱动成功");
}catch(ClassNotFoundException e)
{
e.printStackTrace();
}
String user="root";
String password="gyh2002623";
String url = "jdbc:mysql://localhost:3306/news?useSSL=false&serverTimezone=GMT&characterEncoding=utf-8&autoReconnect=true";
Connection con=null;
try{
con= DriverManager.getConnection(url,user,password);
//System.out.println("数据库连接成功");
}catch(SQLException e)
{
e.printStackTrace();
}
return con;
}
//**********************************************************************
//关闭方法
public static void close (Connection con)
{
try{
if(con!=null)
{
con.close();
}
}catch(SQLException e)
{
e.printStackTrace();
}
}
public static void close(PreparedStatement preparedStatement)
{
try{
if(preparedStatement!=null)
{
preparedStatement.close();
}
}catch(SQLException e)
{
e.printStackTrace();
}
}
public static void close(ResultSet resultSet)
{
try{
if(resultSet!=null)
{
resultSet.close();
}
}catch(SQLException e)
{
e.printStackTrace();
}
}
public static void main(String[] args) throws SQLException
{
}
}

 

posted @   意い十三章  阅读(12)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· DeepSeek在M芯片Mac上本地化部署
点击右上角即可分享
微信分享提示