?? articlesaveaction.java
字號:
package cn.com.blogonline;
import java.io.IOException;
import java.io.PrintWriter;
import java.text.SimpleDateFormat;
import java.util.Date;
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;
public class ArticleSaveAction extends HttpServlet {
public void init(ServletConfig config) throws ServletException {
}
/*
* 處理<GET> 請求方法.
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
//設置接收信息的字符集
request.setCharacterEncoding("UTF-8");
//接收瀏覽器端提交的信息
String title = request.getParameter("title");
String sortid = request.getParameter("sortid");
String content = request.getParameter("content");
int iSortId = 0;
if (sortid!=null) {
iSortId = Integer.parseInt(sortid);
}
DbOperate db=new DbOperate();
/*
* 獲取Blog信息
*/
HttpSession session = request.getSession(true);
Blog blog = (Blog)session.getAttribute(Constants.LOGIN_USER_KEY);
/*
* 設置保存文章信息
*/
Article article=new Article();
article.setTitle(title);
article.setSortid(iSortId);
article.setBlogid(blog.getId());
article.setContent(content);
SimpleDateFormat df = new SimpleDateFormat("MMddhhmmss");
df = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
article.setPubtime( df.format(new Date()));
db.save(article);
/*
*返回結果信息
*/
response.setContentType("text/xml; charset=UTF-8");
response.setHeader("Cache-Control", "no-cache");
//創建輸出流對象
PrintWriter out = response.getWriter();
out.println("發表成功!");
out.close();
}
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 + -