📄 submit.jsp
字号:
<%@ page contentType="text/html; charset=GBK" %>
<%@ page import="java.util.*,java.io.*,java.sql.*"%>
<%@ page import="com.chncup.commen.Log" %>
<%@ page import="com.chncup.commen.DBCon"%>
<%@ page import="java.util.UUID"%>
<%!
/*' ============================================
' 去除Html格式,用于从数据库中取出值填入输入框时
' 注意:value="?"这边一定要用双引号
' ============================================*/
public String inHTML(String str)
{
String sTemp;
sTemp = str;
if(sTemp.equals(""))
{
System.exit(0);
}
sTemp = sTemp.replaceAll("&", "&");
sTemp = sTemp.replaceAll("<", "<");
sTemp = sTemp.replaceAll(">", ">");
sTemp = sTemp.replaceAll("\"", """);
return sTemp;
}
%>
<%
String title=request.getParameter("title")==null?"":request.getParameter("title");
String menu_id = request.getParameter("menu_id")==null?"0":request.getParameter("menu_id");
String content = request.getParameter("content1")==null?"":request.getParameter("content1");
String keywords = request.getParameter("keywords")==null?"0":request.getParameter("keywords");
String description = request.getParameter("description")==null?"":request.getParameter("description");
int iMenuID = 0;
int iNewsID = 1;
int iParentID =1;
try {
iMenuID = Integer.parseInt(menu_id);
} catch(Exception e){
System.out.println("error: " + e);
}
String inContent = inHTML(content);
String message = "";
Connection conn = null;
java.util.UUID uuid = UUID.randomUUID();
String sUUID = uuid.toString();
try {
DBCon db = new DBCon();
conn = db.getConnection();
String path_htm="D:\\www\\eng.chncup.com\\2008.chncup.com\\temp\\";
File d=new File(path_htm);
if(!d.exists()) {
d.mkdir();
}
String sFile ="D:\\www\\eng.chncup.com\\2008.chncup.com\\temp\\"+sUUID+".txt";
FileWriter fw = new FileWriter(sFile);
fw.write(content);
fw.close();
String sql=null;
PreparedStatement prestmt=null;
sql="insert into web_news(title,keywords,description,menu_id,file_length,uuid,filetype) values(?,?,?,?,?,?,?)";
prestmt =conn.prepareStatement(sql);
/*title = new String(title.getBytes("GBK"),"ISO-8859-1");
prestmt.setString(1,title);
//prestmt.setBinaryStream(2,fis,(int)file.length());
//setBinaryStream
//String tempContent = new String(content.getBytes("GBK"),"ISO-8859-1");
//PreparedStatement.setString(2,tempContent);
//PreparedStatement.setString(2,inContent);
prestmt.setBinaryStream(2,fis,(int)file.length());
prestmt.setInt(3,iMenuID);
prestmt.setInt(4,(int)file.length());
*/
//title = new String(title.getBytes("GBK"),"ISO-8859-1");
prestmt.setString(1,title);
//keywords = new String(description.getBytes("GBK"),"ISO-8859-1");
prestmt.setString(2,keywords);
//description = new String(description.getBytes("GBK"),"ISO-8859-1");
prestmt.setString(3,description);
//prestmt.setString(4,'0x');
prestmt.setInt(4,iMenuID);
prestmt.setInt(5,0);
prestmt.setString(6,sUUID);
String filetype = ".txt";
prestmt.setString(7,filetype);
prestmt.executeUpdate();
message = "操作成功!";
Statement stmt = null; // The JDBC Statement object
ResultSet rs = null;
String textCopySQL= "exec sp_textcopy 'localhost','chncup_cn','chncup_cn69#$','chncup_cn','web_news','content','"+sFile+"','where uuid=''"+sUUID+"''',i";
try{
stmt=conn.createStatement();
stmt.executeUpdate(textCopySQL);
}
catch(Exception e){
com.chncup.commen.Log.getLogger().error("insert失败:" + e.getMessage()+" textCopySQL = " + textCopySQL);
}
String sGetNewIDSQL= "select news_id from web_news where uuid='"+sUUID+"'";
try{
stmt=conn.createStatement();
rs = stmt.executeQuery(sGetNewIDSQL);
if (rs.next()){
iNewsID = rs.getInt("news_id");
// iParentID = rs.getInt("parent_id");
}
}
catch(Exception e){
com.chncup.commen.Log.getLogger().error("获取news_id失败:" + e.getMessage()+" sGetNewIDSQL = " + sGetNewIDSQL);
}
}
catch(Exception e){
message = "操作失败!";
System.out.println("error: " + e);
}
String jump_url="";
/* if (message.equals("操作失败!")) {
jump_url="news_add.jsp";
} else {
jump_url="/admin/news/publish_news.jsp?news_id="+iNewsID+"&menu_id="+iMenuID+"&parent_id="+iParentID;
}
*/
/*/////////////////////////////
*
*
*
/////////////////////////////*/
String sql_1="select a.title,a.keywords,a.description,a.file_length,a.menu_id,a.uuid,b.menu_url,b.menu_name,b.parent_id,b.parent_name,b.parent_url,b.type_id from web_news a,view_www_menu b where a.news_id="+ iNewsID + " and a.menu_id=b.menu_id";
Statement stmt_1 = null;
ResultSet result_1 =null;
try {
stmt_1 = conn.createStatement();
result_1 = stmt_1.executeQuery(sql_1);
}
catch(Exception e){
System.out.println("error: " + e);
}
String menu_url = "";
String parent_url = "";
String type_id = "";
String menu_name ="";
String parent_name ="";
//iParentID = 0;
try {
if (result_1.next()) {
title = result_1.getString("title");
menu_id = result_1.getString("menu_id");
menu_name = result_1.getString("menu_name");
parent_name = result_1.getString("parent_name");
keywords = result_1.getString("keywords");
description = result_1.getString("description");
sUUID = result_1.getString("uuid");
menu_url = result_1.getString("menu_url");
parent_url = result_1.getString("parent_url");
type_id = result_1.getString("type_id");
iParentID = result_1.getInt("parent_id");
}
conn.close();
}
catch(Exception e){
System.out.println("error: " + e);
}
if (type_id.equals("1")) {
parent_name = "<a href=\"/news_list.jsp?menu_id="+menu_id+">"+parent_name+"</a>";
} else {
parent_name = "<a href=\""+parent_url+"\">"+parent_name+"</a>";
menu_name = "<a href=\""+menu_url+"\">"+menu_name+"</a>";
}
FileReader fr=new FileReader("D:\\www\\eng.chncup.com\\2008.chncup.com\\template\\news.html");
BufferedReader br=new BufferedReader(fr);
String path_htm="D:\\www\\eng.chncup.com\\2008.chncup.com\\news\\"+menu_id+"\\";
File d=new File(path_htm);
if(!d.exists()) {
d.mkdir();
}
String sFileName = "D:\\www\\eng.chncup.com\\2008.chncup.com\\news\\"+menu_id+"\\"+iNewsID+".html";
FileWriter fw = new FileWriter(sFileName);
int find=-1;
int replen=0;
int jump=0;
String sTemp="";
String sTempAll="";
String flag_string="";
String Line=br.readLine();
while(Line!=null)
{
find=Line.indexOf("<!--#title//-->");
if (find!=-1){
flag_string="<!--#title//-->";
jump=flag_string.length();
Line=Line.substring(0,find)+title+Line.substring(find+jump+replen);
}
find=Line.indexOf("<!--#keywords//-->");
if (find!=-1){
flag_string="<!--#keywords//-->";
jump=flag_string.length();
Line=Line.substring(0,find)+keywords+Line.substring(find+jump+replen);
}
find=Line.indexOf("<!--#description//-->");
if (find!=-1){
flag_string="<!--#description//-->";
jump=flag_string.length();
Line=Line.substring(0,find)+description+Line.substring(find+jump+replen);
}
find=Line.indexOf("<!--#parent_id//-->");
if (find!=-1){
flag_string="<!--#parent_id//-->";
jump=flag_string.length();
Line=Line.substring(0,find)+iParentID+Line.substring(find+jump+replen);
}
find=Line.indexOf("<!--#parent_name//-->");
if (find!=-1){
flag_string="<!--#parent_name//-->";
jump=flag_string.length();
Line=Line.substring(0,find)+parent_name+Line.substring(find+jump+replen);
}
find=Line.indexOf("<!--#menu_name//-->");
if (find!=-1){
flag_string="<!--#menu_name//-->";
jump=flag_string.length();
Line=Line.substring(0,find)+menu_name+Line.substring(find+jump+replen);
}
find=Line.indexOf("<!--#content//-->");
if (find!=-1){
flag_string="<!--#content//-->";
jump=flag_string.length();
Line=Line.substring(0,find)+content+Line.substring(find+jump+replen);
}
fw.write(Line);
fw.write("\r\n");
Line=br.readLine();
}
fr.close();
fw.close();
//生成文件结束
//String jump_url = "/news/"+menu_id+"/"+iNewsID+".html";
jump_url = "/admin/news/news_list.jsp";
message = "发布成功!";
%>
<script language="javascript">
function process ( message,url){
alert(message);
self.location = url;
}
</script>
<SCRIPT language="JavaScript" src="../scripts/util.js"></SCRIPT>
<HTML>
<HEAD>
<TITLE>页尾内容发布</TITLE>
</HEAD>
<body onload="javascript: process('<%=message%>','<%=jump_url%>');">
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -