<%String ref = request.getHeader("REFERER");%>
<input type="button" name="returngo" value="/blog/返回上一頁" onclick="javascript:window.location='<%=ref%>'" >
1.
struts Ation中的用法:
Jsp獲取上一頁的url
String url=request.getHeader("Referer");
返回上一頁
mapping.findForward(url);
2.
利用javascript
public String jump( String jump)
{
String url=null;
if(jump=="back")
{
url="javascript:history.go(-1);\n"; //返回上一頁
}
else if(jump=="home")
{
url="javascript:window.location.href='index.jsp';\n"; //返回首頁
}
else if(jump=="")
{
url="";
}
else
{
url="javascript:window.location.href='"+jump+"';\n"; /返回指定頁
}
String script_start="<script language=\"javascript\">\n";
String script_end="</script>";
String go=script_start+url+script_end;
return go;
}
在Ation中用法
response.setContentType("text/html; charset=UTF-8");
response.setHeader("Cache-Control", "no-cache");
PrintWriter out = response.getWriter();
String jump = ju.jump("home");
out.println(jump);
posted on 2008-01-10 14:56
李建軍 閱讀(2958)
評論(0) 編輯 收藏 所屬分類:
jsp