📄 addnewsproc.jsp
字号:
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage=""%>
<jsp:useBean id="myup" scope="page" class="com.jspsmart.upload.SmartUpload" />
<%@page import="
com.aheadedu.fen.bean.*,
com.aheadedu.fen.service.*,
com.jspsmart.upload.*,
com.aheadedu.fen.*
"%><head>
<title>处理中...</title>
</head>
<%
String username=(String)session.getAttribute("username");
%>
<%!
public String charset(String str) {
String string = null;
try {
string = new String(str.getBytes("gb2312"), "iso-8859-1");
} catch (Exception e) {
System.out.println(e.fillInStackTrace());
}
return string;
}
%>
<%
myup.initialize(pageContext);
try{
myup.setMaxFileSize(20*1024*1024);
myup.setDeniedFilesList("bat,jsp,htm,html,exe,,");
myup.upload();
Request r=myup.getRequest();
String title=charset(r.getParameter("title"));
String kind=r.getParameter("kind");
String content=charset(r.getParameter("content"));
String ispub=r.getParameter("ispub");
RandomNumber rn=new RandomNumber();
String newsid="";
News news=new News();
news.setTitle(title);
news.setKind(kind);
news.setContent(content);
news.setIsPub(ispub);
news.setCreator(username);
NewsService ns=new NewsService("jdbc/news");
newsid=ns.insertNews(news);System.out.println(title+" "+content+" "+kind+" "+ispub+"user"+newsid);
if(newsid!=null){
for(int i=0;i<myup.getFiles().getCount();i++){
com.jspsmart.upload.File myFile = myup.getFiles().getFile(i);
if(!myFile.isMissing()) {
String newfilename=rn.getNumber();
NewsFile nf=new NewsFile();
nf.setNewsID(newsid);
nf.setFileName1(charset(myFile.getFileName()));
nf.setFileName2(newfilename+"."+myFile.getFileExt());
nf.setFileSize(Integer.toString(myFile.getSize()));
nf.setCreator(username);
nf.setFilePath(charset(application.getRealPath("/")+"uploadfiles\\"));
nf.setExtension(myFile.getFileExt());
//System.out.println(" "+myFile.getFileExt());
NewsService ns1=new NewsService("jdbc/news");
boolean state= ns1.addFile(nf);
if(state){
myFile.saveAs("/uploadfiles/"+newfilename+"."+myFile.getFileExt(), myup.SAVE_VIRTUAL);
}else{
%>
<script language="javascript">
alert("一个附件添加失败!");
</script>
<% }
}
}
%>
<script language="javascript">
window.close();
</script>
<%
}else{
%>
<script language="javascript">
alert("添加失败!");
location='addnews.jsp';
</script>
<%
}
}
catch(Exception e){
System.out.println(e.fillInStackTrace()+"");
%>
<script language="javascript">
alert("操作失败,请检查附件类型和大小!");
location='addnews.jsp';
</script>
<%
}
%>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -