当前位置:我的异常网» Java Web开发 » 实在做不出来了,100求教高人解决办法
实在做不出来了,100求教高人解决办法
www.myexceptions.net 网友分享于:2013-02-20 浏览:20次
实在做不出来了,100求教高人
目的:点击“我的评论”在main.jsp中出现所有的feedback内容,
feedback表:id,uname,content,pubtime,articleid
left.jsp:
……
……
showFeedbackAction.java:
package cn.com.blogonline;
import java.io.IOException;
import java.util.ArrayList;
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;
import javax.servlet.http.HttpSession;
public class ShowFeedbackAction extends HttpServlet {
public void init(ServletConfig config) throws ServletException {
}
/*
* 处理 请求方法.
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
//设置接收信息的字符集
request.setCharacterEncoding( "UTF-8 ");
//接收浏览器端提交的信息
String articleId = request.getParameter( "articleid ");
String pageId = request.getParameter( "pageid ");
/*
* 文章编号处理
*/
HttpSession session = request.getSession(true);
DbOperatedb=new DbOperate();
int iArticleId = 0;
Article article = null;
if (articleId!=null) {
iArticleId = Integer.parseInt(articleId);
article=db.getArticle(iArticleId);
session.setAttribute(Constants.CUR_ARTICLE_KEY,article);
}
else{
article=(Article)session.getAttribute(Constants.CUR_ARTICLE_KEY);
iArticleId = article.getId();
}
/*
* 页号处理
*/
int iPageId = 0;
int pageCount = 0;
List feedBackList=db.getFeedBacks(iArticleId);
if (pageId!=null) {
iPageId = Integer.parseInt(pageId);
if (iPageId <0) iPageId = 0;
/*
* 获取总页数
*/
if (feedBackList.size()%Constants.ARTICLE_PAGE_SIZE ==0){
pageCount=feedBackList.size() / Constants.ARTICLE_PAGE_SIZE;
}
else{
pageCount=feedBackList.size() / Constants.ARTICLE_PAGE_SIZE+1;
}
if (iPageId> =pageCount) iPageId = pageCount-1;
session.setAttribute(Constants.CUR_PAGEID_KEY,new Integer(iPageId));
文章评论