?? savelogoaction.java
字號:
package cn.com.blogonline;
import java.io.IOException;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import com.jspsmart.upload.SmartUpload;
public class SaveLogoAction extends HttpServlet {
private ServletConfig config;
public void init(ServletConfig config) throws ServletException {
this.config = config;
}
/*
* 處理<GET> 請求方法.
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
/*
* 上傳文件
*/
String imageName = null;
SmartUpload mySmartUpload = new SmartUpload();
try {
// 初始化
mySmartUpload.initialize(config,request,response);
// 上載
mySmartUpload.upload();
// 保存上載文件到指定目錄
mySmartUpload.save("\\images");
imageName = mySmartUpload.getFiles().getFile(0).getFileName();
} catch (Exception e){
System.out.println(e);
}
/*
* 保存信息
*/
HttpSession session = request.getSession(true);
Blog blog = (Blog)session.getAttribute(Constants.LOGIN_USER_KEY);
blog.setImage(imageName);
DbOperate db=new DbOperate();
db.update(blog);
session.setAttribute(Constants.MODIFY_OK_KEY,new Integer(1));
response.sendRedirect("/BlogOnline/adminLogo.jsp");
}
protected void doPost(HttpServletRequest arg0, HttpServletResponse arg1) throws ServletException, IOException {
// TODO 自動生成方法存根
this.doGet(arg0,arg1);
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -