📄 newspageservlet.java
字号:
package Control;
import java.io.IOException;
import java.util.ArrayList;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.zzu.biz.impl.StudentBizImpl;
//新闻分页控制器
public class NewsPageServlet extends HttpServlet {
/**
* Constructor of the object.
*/
public NewsPageServlet() {
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 {
this.doPost(request, response);
}
/**
* 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 {
response.setContentType("text/html");
request.setCharacterEncoding("gbk");
//调用查询的方法
ArrayList list=(ArrayList)new StudentBizImpl().book();
//设置分页信息
String cur = request.getParameter("pagesize");//取得当前页面
if (cur == null) {//判断是否为空
cur = "1";
}
Module.b_PageBean p = new Module.b_PageBean ();//设置分页Bean的属性,得到一个对象
p.setCurrPage(Integer.parseInt(cur));//设置当前页面
p.setAl(list);//设置所有的要显示的数据
if(list.size()>0){
// for(Iterator it=list.iterator();it.hasNext();)
// {
// News news=(News)it.next();
// System.out.println("输出新闻:"+news.getTitle());
// }
request.getSession().setAttribute("arraysearch", p); //放入会话
}
if(list!=null && list.size()!=0){//有结果时转到显示页面
request.getRequestDispatcher("adminNewsList.jsp").forward(request, response);
}else{//无结果时提示无结果
response.sendRedirect("index.jsp");
}
}
public String input(String in)
{
return in==null?"":in;
}
/**
* Initialization of the servlet. <br>
*
* @throws ServletException if an error occure
*/
public void init() throws ServletException {
// Put your code here
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -