javaweb入门---之链接跳转

来源:互联网 发布:丢书大作战矩阵 编辑:程序博客网 时间:2024/06/03 13:23

javaweb入门–之链接跳转

1. a连接
2. jsp跳转
3. request 跳转
jsp:跳转不需要path,从当前路径下出发,不需要点击,立即跳转,url地址不会不会改变

<jsp:forward page="index.jsp"></jsp:forward>

a链接跳转:跳转不需要path,从当前路径下出发,需要点击,地址会改变

<a href="index.jsp">跳往首页index.jsp</a> 

request跳转:跳转不需要path,从当前路径下出发,不需要点击,立即跳转,地址不会改变

    request.setAttribute("msg", "下大雨了");    request.getRequestDispatcher("index.jsp").forward(request, response); 

三种跳转携带参数的方式:
jsp和request:都可以传递session和Attribute

request.setAttribute("msg", "下大雨了");

a链接:在url中拼接参数

<a href="index.jsp?userId=123">跳往首页index.jsp</a>在跳转后的页面index.jsp获取参数:String msg=(String)request.getAttribute("msg");