Java Web传参总结
一、JSP界面中的参数传递
1、 <a>标签:<a href="地址?参数1=值&参数2=值"></a>
2、<form>表单:
<form action="地址" method="post">
<input type="类型" size="宽度" name="传参的属性名">
………………
<input type="submit" value="按钮名称(提交)" name="button1">
</form>
3、<jsp:param>传参
参数传递:<jsp:param name="参数名称" value="参数内容"/>
(一般是配合<jsp:include>或<jsp:forward>使用)
接收参数:<%=request.getParameter("参数名称")%>
4、jsp内置对象传参
String id = request.getParameter("ID");
String num[] = request.getParameterValues("values") ;
使用地址重写的方式传参:动态页面地址?参数名称1=参数内容&参数名称2=参数内容&....
pageContext.setAttribute("name","李雷");
String UserName = (String)pageContext.getAttribute("name");
request.setAttribute("name","李雷");
String UserName = (String)request.getAttribute("name");
session.setAttribute("name","李雷");
String UserName = (String)session.getAttribute("name");
application.setAttribute("name","李雷");
String UserName = (String)application.getAttribute("name");
5、javabean传参
<jsp:useBean id="对象名" class="类名" scope="范围" />
<%
%>
二、servler内传参
HttpServletRequest req;
HttpServletResponse resp;
req.getSession().setAttribute("name","李雷");
String a = (String) req.getSession().getAttribute("name");
req.setAttribute("name","李雷");
String userName = (String)req.getAttribute("userName");
req.getServletContext().setAttribute("name","李雷");
req.getServletContext().getAttribute("name");
三、Cookie传参
Cookie c = new Cookie("UserID","a123");
c.setMaxAge(60*60*24*7);
response.addCookie(c);
String cookieName = "UserID";
Cookie cookies[] = request.getCookies();
if(cookies!=null){
for(int i=0;i<cookies.length;i++){
}
}
本文地址:https://blog.csdn.net/qq_45949914/article/details/109257111