JSP 内置对象的应用 session application 大侠 仗义相助啊!!!

qq_28075231 2015-08-17 04:36:43
利用jsp常用内置对象,当用户任意点击3次超级链接之后,“仅”在第三次点击的页面上显示出所有的浏览路径。
我能控制在第三次上显示信息
可是怎么获取所有的浏览路径啊
下面是我的代码:
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">

<title>2.jsp</title>

<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->

</head>

<body>
<%
int number=0;
Object obj=session.getAttribute("number");
if(obj==null)
session.setAttribute("number",String.valueOf(number));
else{
number=Integer.parseInt(obj.toString());
number+=1;
session.setAttribute("number",String.valueOf(number));
}
while(Integer.parseInt(obj.toString())==3){
%><%=**显示点击过的超链接的浏览路径***
%>
<%

}
%>

<a href="3.jsp">"jump to 3"</a>
<a href="index.jsp">"jump to index"</a>
<a href="1.jsp">"jump to 1"</a>


</body>
</html>
...全文
167 点赞 收藏 7
写回复
7 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
前后端交互你不会吗?后端拿到request对象后,url就可以拿到了
回复
qq_28075231 2015-08-21
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> <% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <base href="<%=basePath%>"> <title>1.jsp</title> <meta http-equiv="pragma" content="no-cache"> <meta http-equiv="cache-control" content="no-cache"> <meta http-equiv="expires" content="0"> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv="description" content="This is my page"> <!-- <link rel="stylesheet" type="text/css" href="styles.css"> --> </head> <body> <% List list=new ArrayList(); String str=new String(); str= basePath+"1.jsp"; int number=1; Object obj=null; if(session.getAttribute("list")==null){ list.add(str); session.setAttribute("list",list); session.setAttribute("number",String.valueOf(number)); } else{ list=(List)session.getAttribute("list"); obj=session.getAttribute("number"); list.add(str); session.setAttribute("list",list); number=Integer.parseInt(obj.toString()); number+=1; session.setAttribute("number",String.valueOf(number)); } while(Integer.parseInt(obj.toString())==3){ %> 浏览路径: <% for(int i=0;i<list.size();i++){ String s=(String)list.get(i); %> <%=s %>    <%} } %> <a href="3.jsp">"jump to 3"</a> <a href="index.jsp">"jump to index"</a> <a href="1.jsp">jump to 2</a> </body> </html> 这是我修改后的代码,while循环好像有点问题
回复
qq_28075231 2015-08-21
怎么将JSP的URL传到后台呢?
回复
在后台每次将http请求的url 存到一个list中,再将list存到session中,下一次请求的时候,先从session中拿到list,然后往list中添加一个url,再把list存到session中,前台可以根据session中的list的size得到用户点击的次数,list的size为3就做显示
回复
这个东西应该需要后台来支持,在后台你将他每次的http请求中的url获取到并存储到session中,在前端获取url的数量,如果为3就显示。仅仅在前端做好像有点困难吧
回复
点击啥超链接?你是在你的页面上有多个超链接,然后人家任意点击其中的三个就显示他点击过的三个超链接吗?
回复
qq_28075231 2015-08-20
我修改了一下,还是有错误,大家帮忙看一看,我那个session好像不太对,要怎么改啊!!!! <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> <% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <base href="<%=basePath%>"> <title>index.jsp</title> <meta http-equiv="pragma" content="no-cache"> <meta http-equiv="cache-control" content="no-cache"> <meta http-equiv="expires" content="0"> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv="description" content="This is my page"> <!-- <link rel="stylesheet" type="text/css" href="styles.css"> --> </head> <body> <% List list=null; int number=1; Object obj=null; if(session.getAttribute("list")==null){ session.setAttribute("list",basePath); session.setAttribute("number",String.valueOf(number)); } else{ list=(List)session.getAttribute("list"); obj=session.getAttribute("number"); list.add(basePath); number=Integer.parseInt(obj.toString()); number+=1; session.setAttribute("number",String.valueOf(number)); } while(Integer.parseInt(obj.toString())==3){ %> 浏览路径: <% for(int i=0;i<list.size();i++){ String s=(String)list.get(i); %> <%=s %>    <%} } %> <a href="3.jsp">"jump to 3"</a> <a href="2.jsp">"jump to 2"</a> <a href="1.jsp">"jump to 1"</a> </body> </html>
回复
相关推荐
发帖
Web 开发
创建于2007-09-28

8.0w+

社区成员

Java Web 开发
申请成为版主
帖子事件
创建了帖子
2015-08-17 04:36
社区公告
暂无公告