永发信息网

一个jsp问题??求解呀。。为什么currentPage 一直等于1呢??

答案:3  悬赏:0  手机版
解决时间 2021-01-03 14:09
  • 提问者网友:了了无期
  • 2021-01-02 13:51
前台传值是这样的:
<a href="/mywork/selectVendor?currentPage =<%=request.getAttribute("currentPage")%>+1 ">下一页</a> |
后台接收
package myservlet;

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 bean.Vendor;
import dao.VendorDAO;
public class selectVendor extends HttpServlet
{

public int currentPage = -1;
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
//System.out.println("3333333");
response.setContentType("text/html;charset=utf-8");
request.setCharacterEncoding("utf-8");

String searchName = request.getParameter("vendorName");
VendorDAO vendorDao = new VendorDAO();
doGet(request, response);
System.out.println("hello");
System.out.println(currentPage);
ArrayList<Vendor> rs = vendorDao.searchVendor(searchName,currentPage);
int pageCount = vendorDao.getPageCount(5);
request.setAttribute("pageCount",pageCount);
request.setAttribute("rs",rs);
request.setAttribute("currentPage",1);
if(rs != null)
{ request.getRequestDispatcher("/coe/bim/vendorManagement.jsp").forward(request,response);

}

}

public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
String current =request.getParameter("currentPage");
if(current == null)
{
currentPage = 1;

}
else
{
currentPage = Integer.parseInt(current);
}
}
}
最佳答案
  • 五星知识达人网友:蕴藏春秋
  • 2021-01-02 14:16
<a href="/mywork/selectVendor?currentPage =<%=request.getAttribute("currentPage")%>+1 ">

这一句有点问题。修改成这样最好:

<a href=’/mywork/selectVendor?currentPage =<%=request.getAttribute("currentPage")%>+1 ’>
外面单引号,里面套上双引号
全部回答
  • 1楼网友:忘川信使
  • 2021-01-02 16:46
request.setAttribute("currentPage",1); 这里你不就是这么写的吗
  • 2楼网友:举杯邀酒敬孤独
  • 2021-01-02 15:33
你好! request.setAttribute("currentPage",1); 这里你不就是这么写的吗 我的回答你还满意吗~~
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯