📄 save.jsp
字号:
<%@ page import="java.io.*" %>
<%@ include file="base64.jsp" %>
<%
/*--------------------------------------------------------------------
This script accepts the image from the hidden field 'image'.
The image data are BASE64 encoded. The script decodes it
to binary byte array and saves it to a disk file.
The text notes (field "notes") are saved to the file "notes.txt"
---------------------------------------------------------------------*/
// Image and notes are saved in the script's directory,
// but you can assign any directory, for example: saveDir = "mydir";
File saveDir = new File(application.getRealPath(request.getServletPath())).getParentFile();
String imageFilename = "image.png";
String notesFilename = "notes.txt";
// save the image
String base64EncodedImage = request.getParameter("image");
byte imageBytes[] = Base64Decode(base64EncodedImage);
OutputStream os = new FileOutputStream(new File(saveDir,imageFilename));
try {
os.write(imageBytes);
}
finally {
os.close();
}
// save the text notes
String notes = request.getParameter("notes");
PrintWriter writer = new PrintWriter(new FileOutputStream(new File(saveDir,notesFilename)));
try {
writer.print(notes);
}
finally {
writer.close();
}
%>
<html>
<head>
<title>J-Painter. JSP Example 2</title>
</head>
<body>
<p><img src="<%=imageFilename%>" border=1>
<br>Image is saved to <%=imageFilename%></p>
<p>Notes are saved to <a href="<%=notesFilename%>" target="_blank"><%=notesFilename%></a></p>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -