int pageMax=3;
int pageIndex=1;
MesBiz mes=new MesBizImpl();String str=(String)session.getAttribute("indexes");
(报错的语句:java.lang.Integer cannot be cast to java.lang.String)if(str!=null){
pageIndex=Integer.parseInt(str);
}
刚进页面的时候正常运行str为null当提交后再跳转回来 session.getAttribute("indexes"); 为2!(已经确定为2了)
但把它转换为String时错误!
下面是完整代码:
Main.jsp页面<%
int pageMax=3;
int pageIndex=1;
MesBiz mes=new MesBizImpl();
String str=(String)session.getAttribute("indexes");
if(str!=null){
pageIndex=Integer.parseInt(str);
}
List<Message> list=mes.showMes(pageMax,pageIndex);
request.setAttribute("Messages",list);
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title></title>
</head>
<body>
<h3></h3>
<c:set var="mesage" value="${requestScope.Messages}" scope="request"></c:set>
<c:forEach var="mes" items="${requestScope.mesage}" varStatus="status">
<div>
<div style>作者:${mes.author}</div>
<div>文章:${mes.mesText}</div>
</div>
</c:forEach>
<div>
<ul>
<a href="turnPage.jsp?turn=1">上一页</a>
<a href="turnPage.jsp?turn=<%=(pageIndex+1)%>">下一页</a>
</ul>
</div>
<hr/>
</body>
</html>
turnPage.jsp页面
<html>
<head>
<title>处理分页</title>
</head>
<body>
<%
request.setCharacterEncoding("GBK");
String index=request.getParameter("turn");
if(index!=null){
int pageIndex=Integer.valueOf((String)request.getParameter("turn"));
session.setAttribute("indexes",pageIndex);
response.sendRedirect("Main.jsp");
}else{
out.print("出错");
}
%>
</body>
</html>
int pageIndex=1;
MesBiz mes=new MesBizImpl();String str=(String)session.getAttribute("indexes");
(报错的语句:java.lang.Integer cannot be cast to java.lang.String)if(str!=null){
pageIndex=Integer.parseInt(str);
}
刚进页面的时候正常运行str为null当提交后再跳转回来 session.getAttribute("indexes"); 为2!(已经确定为2了)
但把它转换为String时错误!
下面是完整代码:
Main.jsp页面<%
int pageMax=3;
int pageIndex=1;
MesBiz mes=new MesBizImpl();
String str=(String)session.getAttribute("indexes");
if(str!=null){
pageIndex=Integer.parseInt(str);
}
List<Message> list=mes.showMes(pageMax,pageIndex);
request.setAttribute("Messages",list);
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title></title>
</head>
<body>
<h3></h3>
<c:set var="mesage" value="${requestScope.Messages}" scope="request"></c:set>
<c:forEach var="mes" items="${requestScope.mesage}" varStatus="status">
<div>
<div style>作者:${mes.author}</div>
<div>文章:${mes.mesText}</div>
</div>
</c:forEach>
<div>
<ul>
<a href="turnPage.jsp?turn=1">上一页</a>
<a href="turnPage.jsp?turn=<%=(pageIndex+1)%>">下一页</a>
</ul>
</div>
<hr/>
</body>
</html>
turnPage.jsp页面
<html>
<head>
<title>处理分页</title>
</head>
<body>
<%
request.setCharacterEncoding("GBK");
String index=request.getParameter("turn");
if(index!=null){
int pageIndex=Integer.valueOf((String)request.getParameter("turn"));
session.setAttribute("indexes",pageIndex);
response.sendRedirect("Main.jsp");
}else{
out.print("出错");
}
%>
</body>
</html>
解决方案 »
- 关于论坛回复楼层显示的实现
- spring aop 切入点表达式问题
- 如何从类似:'关于计算机技术和电脑技术的关系'中智能地提取出:计算机,技术,电脑,关系 关键字?
- String.formate在Java和C#中的区别
- 部门管理问题
- jsp 如何获得 select MULTIPLE 中的值
- jsp+javabean项目的部署问题,急!
- 初学者,请各位英雄帮帮小弟啊!!!
- 在struts结构中,如何jsp页面中调用action中bean的方法,请指点.
- 保存到HashMap中的数据怎样在本业提取后保存到数据库中?
- 我要搭建SSH框架,用SQL05数据库,出问题,求救。
- jsp页面传递NULL值出错?
是不是
request就用(String)来转
session就用toString()来转的?