📄 photo_save.jsp
字号:
<%@ page contentType="text/html"%>
<%@ page pageEncoding="UTF-8"%>
<%@ include file="Config.jsp" %>
<%@ page import="java.io.*" %>
<%@ page import="java.util.*" %>
<%@ page import="java.text.*" %>
<%@ page import="com.jspsmart.upload.*"%>
<%@ include file="../../mBase/Config.jsp" %>
<%
String photo_name="";
String photo_file="";
String path_photo="";
Date nowtime=new Date();
SimpleDateFormat formatter=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String strdate=formatter.format(nowtime);
SimpleDateFormat formatter1=new SimpleDateFormat("yyyyMMddHHmmss");
String strfilename=formatter1.format(nowtime);
String pathP = BaseDB +mUrl + "pic/"; //建立代表目前目录位置的d变量
String path_pic=request.getRealPath( pathP );
if(request.getMethod().equals("POST")){
String ok = "<script language=\"javascript\">alert(\"上传成功\");</script>";
String fail = "<script language=\"JavaScript\">alert(\"上传失败!请上传gif、jpg格式!文件不能大于1M\");</script>";
try {
SmartUpload uploader=new SmartUpload();
uploader.initialize(pageContext);//初始化
uploader.setMaxFileSize(3024000);
uploader.setAllowedFilesList("jpg,gif,JPG,GIF");
uploader.upload();
photo_name=uploader.getRequest().getParameter("photo_name");
photo_name = new String(photo_name.getBytes("gbk"),"utf-8");
String photo_type=uploader.getFiles().getFile(0).getFileExt();
photo_file = strfilename +"."+ photo_type ;
com.jspsmart.upload.File file = uploader.getFiles().getFile(0);
path_photo =path_pic+ "/"+ photo_file;
file.saveAs(path_photo);
out.print(ok);
} catch (Exception e) {
log(e.getMessage());
out.print(fail);
}
// photo_name="无法使用【 jspSmartUpload.jar 】测试数值";
}
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title><%=photo_name%>::<%=nTitle%></title>
<LINK REL="stylesheet" HREF="../../images/szpay.css" TYPE="text/css">
</head>
<body>
<center>
<jsp:include page="../../mBase/Head_2.jsp"/>
<DIV class="w">
<H1>标题:<%=photo_name%></H1>
</DIV>
<jsp:include page="../../mBase/AD_928x90_top.jsp"/>
<DIV id="photo">
<h2><%=photo_name%></h2>
<img border="0" src="/<%=BaseDB%><%=mUrl%>pic/<%=photo_file%>" title="<%=photo_name%>">
<%
String szname="游客";
String szNote="";
Cookie cookies[]=request.getCookies();
Cookie sCookie=null;
if(cookies!=null) {
for(int i=0;i<cookies.length; i++)
{
sCookie=cookies[i];
if(sCookie.getName().equals("szpay"))
{
szname=java.net.URLDecoder.decode(sCookie.getValue(), "UTF8");
}
if(sCookie.getName().equals("note"))
{
szNote=java.net.URLDecoder.decode(sCookie.getValue(), "UTF8");
}
}
}
String pathT = BaseDB +mUrl + "txt/"; //建立代表目前目录位置的d变量
String path_txt=request.getRealPath( pathT );
java.io.File d = new java.io.File(path_txt);//取得代表目录中所有文件
java.io.File list[] = d.listFiles();
int count = list.length;
count = count + 1;
%>
<DIV id="Note">
作者签名:<BR />
<%=szNote%>
</DIV>
</DIV>
<DIV id="nav" class="w">
<DIV class="l">
<span class="cBlue">[第<%=count%>楼]</span> 作者:<B><%=szname%></B> IP地址:<span class="cGreen"><%=request.getRemoteAddr()%></span>
</DIV>
<DIV class="r">
发布时间:<span class="cBlue"><%=strdate%></span>
</DIV>
</DIV>
<%
String filecontent="<DIV id=\"photo\">\r\n";
filecontent+= "<h2>" + photo_name + "</h2>\r\n";
filecontent+= "<img border=\"0\" src=\"/bbs/"+ BaseDB + mUrl +"pic/" + photo_file + "\" title=\"" + photo_name + "\">\r\n";
filecontent+= "<DIV id=\"Note\">";
filecontent+= "作者签名:<BR />" + szNote + "\r\n";
filecontent+= "</DIV>\r\n";
filecontent+= "</DIV>\r\n";
filecontent+= "<DIV id=\"nav\" class=\"w\">\r\n";
filecontent+= "<DIV class=\"l\">\r\n";
filecontent+= "<span class=\"cBlue\">[第" + count + "楼]</span> 作者:<B>" + szname + "</B> IP地址:<span class=\"cGreen\">" + request.getRemoteAddr() + "</span>\r\n";
filecontent+= "</DIV>\r\n";
filecontent+= "<DIV class=\"r\">\r\n";
filecontent+= "发布时间:<span class=\"cBlue\">" + strdate + "</span>\r\n";
filecontent+= "</DIV>\r\n";
filecontent+= "</DIV>\r\n";
String path_cell=path_txt + "/"+ strfilename +".txt";
try{
FileOutputStream fos = new FileOutputStream(path_cell);
Writer pw = new OutputStreamWriter(fos);
pw.write( filecontent );
pw.close();
fos.close();
}
catch( IOException e ) {
out.println(e.getMessage());
}
%>
<jsp:include page="../../mBase/AD_928x90_down.jsp"/>
<jsp:include page="../../mBase/Footer_20.jsp"/>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -