📄 updatenewsproc.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.*
"%>
<%
String username=(String)session.getAttribute("username");
if(username==null || username.equals("")){
%>
<script language="javascript">
location='../index.jsp';
</script>
<%
}
%>
<%
String newsid=(String)session.getAttribute("newsid");
if(newsid==null){
%>
<script language="javascript">
location='index.jsp';
</script>
<%
}
%>
<table width="391" height="465" border="0" align="center">
<tr>
<td width="385" height="217"> </td>
</tr>
<tr>
<td></td>
</tr>
</table>
<%!
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;
}
%>
<%
RandomNumber rn=new RandomNumber();
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");
News news=new News();
news.setNewsID(newsid);
news.setTitle(title);
news.setKind(kind);
news.setContent(content);
news.setIsPub(ispub);
NewsService ns=new NewsService("jdbc/news");
boolean b=ns.updateNews(news);
if(b){
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='modify.jsp?newsid=<%=newsid%>';
</script>
<%
}
}
catch(Exception e){
%>
<script language="javascript">
alert("操作失败,请检查附件类型和大小!");
location='modify.jsp?newsid=<%=newsid%>';
</script>
<%
}
%>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -