jsp 返回上一页

<%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);

你可能感兴趣的:(JavaScript,java,jsp,struts,Go)