save.jsp
来自「applet在線上繪圖,允許在瀏覽器上繪圖,最後儲存成各式的圖檔」· JSP 代码 · 共 40 行
JSP
40 行
<%@ page import="java.io.*" %>
<%@ include file="base64.jsp" %>
<%
/*--------------------------------------------------------------------
This script accepts the image from the posted parameter 'image'.
The image data are BASE64 encoded so the script has to decodes it
to binary byte array. Then itsaves it to a disk file.
Then the script asks the applet to redirect the browser to the 'view.htm'
to prove that the image is saved successfully. For that it outputs
the command:
#SHOWDOCUMENT=view.htm
---------------------------------------------------------------------*/
// get the submitted image data
String image = request.getParameter("image");
if (image != null) {
// get image bytes
byte imageBytes[] = Base64Decode(image);
// This script saves the image to the script's directory as 'image.png',
// but you can use any desirable file name and destination directory.
File saveDir =
new File(application.getRealPath(request.getServletPath())).getParentFile();
String filename = "image.png";
OutputStream os = new FileOutputStream(new File(saveDir,filename));
os.write(imageBytes);
os.close();
// Redirect the browser to the 'view.html' to display the saved image
out.println("#SHOWDOCUMENT=view.htm");
}
else
out.println("#SHOWSTATUS=Image is not found in the request");
%>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?