?? firstaction.java
字號:
package cn.com.blogonline;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class FirstAction extends HttpServlet {
public void init(ServletConfig config) throws ServletException {
}
/*
* 處理<GET> 請求方法.
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
//利用hibernate查詢熱點博客和最新文章
DbOperate db=new DbOperate();
List blogList=db.getBlogs(10);
List artileList=db.getArticles(10);
//設置輸出信息的格式及字符集
response.setContentType("text/xml; charset=UTF-8");
response.setHeader("Cache-Control", "no-cache");
//創(chuàng)建輸出流對象
PrintWriter out = response.getWriter();
//依據(jù)驗證結果輸出不同的數(shù)據(jù)信息
out.println("<response>");
/*
* 輸出熱點博客
*/
Blog curBlog=null;
for (int i=0;i<blogList.size();i++){
curBlog = (Blog)blogList.get(i);
out.println("<blog>");
out.println("<id>" + curBlog.getId() + "</id>");
out.println("<name>" + curBlog.getSubject() + "</name>");
out.println("</blog>");
}
/*
* 輸出最新文章
*/
Article curArticle=null;
for (int i=0;i<artileList.size();i++){
curArticle = (Article)artileList.get(i);
out.println("<article>");
out.println("<id>" + curArticle.getId() + "</id>");
out.println("<title>" + curArticle.getTitle() + "</title>");
out.println("<time>" + curArticle.getPubtime() + "</time>");
out.println("</article>");
}
out.println("</response>");
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 + -