⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 savenews.jsp

📁 该源码为JSP的开发案例集锦
💻 JSP
字号:
 <%@ page contentType="text/html; charset=gb2312"%>
<%@ include file="verify.jsp" %>
<%@ include file="../share/connection.jsp" %>
<%@ include file="../share/function.jsp" %>
<%@ include file="../share/function_filename.jsp" %>
<%@ page import="java.util.Calendar"%> 
<%@ page import="java.io.*"%>
<%@ page import="javax.servlet.http.*"%>
<%@ page import="javax.servlet.*"%>
<%@ page import="javax.servlet.ServletInputStream"%>
<%@ page import="java.util.*"%>
<%@ page import="sun.net.ftp.*"%>
<%@ page import="sun.net.*"%>
<%
String name = (String)session.getAttribute("adminname");
String news_ip = (String)session.getAttribute("user_ip");
//String news_ip=new String(news1_ip.getBytes("ISO8859_1"));
if(!name.equals("admin"))
{
	out.println("您没有此权限");
	return; 
}
%>
<title>保存新闻</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<%
String newstitle=request.getParameter("newstitle");
String content=request.getParameter("content");
String temp=request.getParameter("AttFiles_p");
String temp1=new String(temp.getBytes("ISO8859_1"));
String temp2=new String();
String temp3=new String();
String temp_depart=new String();
if(newstitle==null||newstitle.length()==0)
{
	out.print("标题不能为空");
	return;
}
/*if(content==null||content.length()==0)
{
	out.print("内容不能为空");
	return;
}*/
if(content==null || content.length()==0)
{  
 //2003-09-16  if (temp==null || temp.length()==0)
//	 {
	  out.print("新闻内容不能为空");
	  return;
//	  }
//   else
//      content=new String("<静态新闻>".getBytes("GBK"),"ISO8859_1");
//      content=new String("详细内容请点击下列文件:".getBytes("GBK"),"ISO8859_1");
}

newstitle=myTools.addSlashes(newstitle);
content=myTools.addSlashes(content);
String userid=(String)session.getAttribute("userid");
String departid=(String)session.getAttribute("userdepartid");
String ishtml=request.getParameter("ishtml")==null?"0":"1";
String attachfile_name=new String();
int  news_id=0;
int  n_pos=0;
Calendar cal=Calendar.getInstance();
String addDate=cal.get(cal.YEAR)+"-"
          +(cal.get(cal.MONTH)+1)+"-"
          +cal.get(cal.DAY_OF_MONTH)+"-"
		   +(cal.get(cal.HOUR_OF_DAY))+":"
		  +(cal.get(cal.MINUTE))+":"
		   +(cal.get(cal.SECOND));
String sqlNews="INSERT INTO cs_news(news_userid,news_departid, "
	+"news_title, news_ip,news_content,news_level, "
	+"news_ispublic,news_adddate,news_ishtml) VALUES("
	+userid+","//userid for admin
	+departid+","//depart id
	+"'"+newstitle+"'," //news title
	+"'"+news_ip+"',"
	+"'"+content+"'," //news content
	
	+"1," //default level
	+"1," //news is public
	+"'"+addDate+"',"
	+ishtml+")";// add date
String sqlSelect_News="SELECT news_id FROM cs_news WHERE news_departid="
                      +departid+" AND news_userid="+userid+" AND news_title='"
					  +newstitle+"'";
String sqlSelect_departlink="SELECT depart_link FROM cs_depart WHERE depart_id="
                      +departid;
String sqlSelect_ftpServer="SELECT * FROM cs_ftpserver";
String departlink=new String();
ResultSet counters=null,counters_depart=null,counters_ftp=null;
String server = new String();
int port = 0;
String user = new String();
String passwd = new String();
String filename="G:\\文件上载_news\\"+userid+"_";
int succ_flag=0;
//        {
//		   if (content.equals(new String("<静态新闻>".getBytes("GBK"),"ISO8859_1")))
//2003-09-16  if (content.equals(new String("详细内容请点击下列文件:".getBytes("GBK"),"ISO8859_1")))
       if (temp!=null && temp.length()!=0)
		   {
        		   if(stm.executeUpdate(sqlNews)==1)
		              succ_flag=1;
		           else
		              succ_flag=0;//out.print("添加新闻失败");
         // out.print("添加新闻成功");
             counters = stm.executeQuery(sqlSelect_News);
             if (counters.next())
	 	        news_id = counters.getInt(1);
             counters.close();
             counters_depart = stm.executeQuery(sqlSelect_departlink);
             if (counters_depart.next())
	 	        departlink = counters_depart.getString(1);
             counters_depart.close();
             counters_ftp = stm.executeQuery(sqlSelect_ftpServer);
             if (counters_ftp.next())
		     {
	 	       server = counters_ftp.getString(1);
	 	       port = counters_ftp.getInt(2);
	 	       user = counters_ftp.getString(3);
	 	       passwd = counters_ftp.getString(4);
			  }
             counters_ftp.close();
    	     int len=0;
	         int len1=0;
		     int i=0,j=0,k=0;
		     for (i=0;i<departlink.indexOf('/');i++)
		    {
		        temp_depart=temp_depart+departlink.charAt(i);
		     }
		     for (i=0;i<10;i++)
		    {  len=0;
		       len1=0;
	 		   for(j=k;j<temp1.length();j++)
		        { if (temp1.charAt(j)=='\n')
		             break;
		             temp2=temp2+temp1.charAt(j);
			     }
	           String s="";
               String localFile=new String();
               localFile=temp2;
			   k=j+1;
			   if (k<temp1.length())
			   localFile=temp2.substring(0,localFile.length()-1);
               len=temp2.length();
               for(int j1=0;j1<len;j1++)
            	 {
	               s="";
	               s=s+temp2.charAt(j1);
	               if (s.equals("\\"))
		             { 
					   len1 = j1;
		               continue;
		              }
	              }
	           for(int j1=len1;j1<len;j1++)
	             {
	               temp3 = temp3+temp2.charAt(j1);
		          }
		       attachfile_name=new String(temp3.getBytes("GBK"),"ISO8859_1");
			   String a="";
//			   out.println("remoteFile"+temp3);
              // String remoteFile = "/test/csnews/"+temp_depart+"/static_news/"+temp3;
    		   String remoteFile = "/xywz/csnews/"+temp_depart+"/static_news/"+temp3;
 
			   try{
   	             FtpClient client = new FtpClient(server,port);
                   client.login(user,passwd);
                   client.binary();
                   TelnetOutputStream out1=client.put(remoteFile);
				  // out.println("localFile:"+filename+localFile);
                   File file_in= new File(filename+localFile);
                   DataInputStream is = new DataInputStream(new FileInputStream(file_in));
                   byte[] bytes = new byte[is.available()];
                   is.readFully(bytes);
                   is.close();
                   out1.write(bytes);
                   out1.close();
                   client.closeServer() ;
                   String sqlattach_News="INSERT INTO cs_news_attachfile(news_id,attachfile_name,attachfile_path) VALUES("
                                     +news_id+",'"+attachfile_name+"','"+temp_depart+"')";
         	       stm.executeUpdate(sqlattach_News);	
    	           temp2="";
    	           temp3="";
    			   if (k>temp1.length())
    			      break;
 			   }
		       catch (IOException e)
			   {
			     a="输入输出:失败!";
			     out.println(a+"--e--"+e+"--i--"+i);
				 out.print("添加新闻失败!");
		        }
		     }
        		   if(succ_flag==1)
		              out.print("添加新闻成功");
		           else
		              out.print("添加新闻失败");
		   }
		   else
		      {
            	if(stm.executeUpdate(sqlNews)==1)
                   out.print("添加新闻成功");
            }
%>
</body>
</html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -