JSP内置对象

post发送方式

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
    <form action="request-receiver.jsp" method="post">
        username:<input  type="text" name="user"/><br/>
        password:<input  type="password" name="pwd"/><br/>

        <input  type="submit" name="登陆"/>        

    </form>
</body>
</html>

获取数据

<%
//获取请求数据
//设置请求方式的编码
request.setCharacterEncoding("UTF-8");
String name = request.getParameter("user");
String pwd = request.getParameter("pwd");
System.out.println(name+","+pwd);

if("smyh".equals(name) && "007".equals(pwd)) {
    out.println("登陆成功");    
}else{
    out.println("errors");
}
%>

页面转发:

request.getRequestDispatcher("request-success.jsp").forward(request, response);

页面跳转

response.sendRedirect("页面");

重定向和转发:

重定向的意思是说,当页面进行跳转之后,request和response的生命周期已经结束,完全交给下一个页面去处理了(连url都变了);而转发的时候,还可以往request里面添加携带参数(url不变)。

//设置请求方式的编码

request.setCharacterEncoding("UTF-8");

request中可以存数据,session中也可以存数据。如果是保存用户名信息等,可以存到session中;如果只需要传递数据(从这个页面传到另一个页面),就可以放在request中转发出去,避免内存浪费。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值