?? savelogo.java
字號:
package cn.Blogonline;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.jsp.PageContext;
import com.jspsmart.upload.*;
public class SaveLogo extends HttpServlet {
private ServletConfig config;
public SaveLogo() {
super();
}
/**
* Destruction of the servlet. <br>
*/
public void destroy() {
super.destroy(); // Just puts "destroy" string in log
// Put your code here
}
/**
* The doGet method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to get.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out
.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">");
out.println("<HTML>");
out.println(" <HEAD><TITLE>A Servlet</TITLE></HEAD>");
out.println(" <BODY>");
out.print(" This is ");
out.print(this.getClass());
out.println(", using the GET method");
out.println(" </BODY>");
out.println("</HTML>");
out.flush();
out.close();
}
/**
* The doPost method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to post.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
//request.setCharacterEncoding("GBK");
// System.out.println(this.getServletContext().getServletContextName());
// System.out.println(this.getServletConfig().getServletName());
String imageName = null;
SmartUpload myupload = new SmartUpload();
myupload.initialize(this.getServletConfig(),request,response);
try {
myupload.setAllowedFilesList("gif,jpg");//設定允許上傳的文件(通過擴展名限制)
myupload.setMaxFileSize(20000);//設定允許最大上傳文件的大小-20000字節(20k)
myupload.upload();
myupload.save("images");
imageName = myupload.getFiles().getFile(0).getFileName();
//System.out.println(imageName);
} catch (SmartUploadException e) {
// TODO 自動生成 catch 塊
e.printStackTrace();
}
BlogSelf blog = new BlogSelf();
blog.setImage("images/"+imageName);
blog.setId(3);
DAO db = new DAO();
db.UpdateBlogLogo(blog);
response.sendRedirect("/BlogOnline/admin/adminLogo.jsp");
}
/**
* Initialization of the servlet. <br>
*
* @throws ServletException if an error occure
*/
public void init() throws ServletException {
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -