JSP 简单的新闻发布系统
在安装的tomcat文件夹下的webapps\JSP_DB(这个是我的)下面建文件夹news
MySQL数据库中建database new 建表news
create table news(title varchar(100),fileName varchar(500));
//创建pub.jsp
<%@ page language="java" import="java.util.*" pageEncoding="GB2312"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>简单新闻发布系统</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body>
<center>
<form action="pub_do.jsp" method="post">
<table width="600" border="0">
<tr>
<th scope="col">新闻发布系统</th>
</tr>
<tr>
<td><div align="center">新闻标题:
<input name="title" type="text" size="60"/>
</div></td>
</tr>
<tr>
<td><hr size="2" /></td>
</tr>
<tr>
<td><div align="center">新闻内容</div></td>
</tr>
<tr>
<td><div align="center">
<textarea name="content" rows="15" cols="65"></textarea>
</div></td>
</tr>
<tr>
<td><hr size="2"/></td>
</tr>
<tr>
<td><div align="center">
<input type="submit" name="Submit" value="发布" />
</div></td>
</tr>
</table>
</form>
</center>
</body>
</html>
//创建pub_do.jsp
<%@ page language="java" import="java.util.*" pageEncoding="GB2312"%>
<%@page import="java.io.*" %>
<%@page import="java.sql.*"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>发布页面</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body>
<%!
//根据提交的内容创建HTML文件
private void createFile(String title,String content,File file)throws IOException,SQLException{
if(!file.exists()){
file.createNewFile();//创建新文件
}
PrintWriter pw=new PrintWriter(new FileOutputStream(file));//输出流
pw.println("<title>"+title+"</title>");//向文件写入新闻标题
pw.println(content);//向文件写入新闻的内容
pw.close();//关闭输出流
}
%>
&