form表单+EL表达式+过滤器+foreach标签
Posted broadencoder
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了form表单+EL表达式+过滤器+foreach标签相关的知识,希望对你有一定的参考价值。
form表单:
<form action="NewFile3.jsp" method="get">
姓名:<input type="text" name="name"><br>
密码:<input type="password" name="pwd"><br>
性别:<input type="radio" name="sex" value="man">男<br>
<input type="radio" name="sex" value="woman">女<br>
年龄:<select name="age">
<option value="10" >10
<option value="20"> 20
<option value="30">30
<option value="40">40
<option value="50">50
<option value="60">60
</select><br>
爱好:
<input type="checkbox" name="habit" value="book">看书
<input type="checkbox" name="habit" value="game">游戏
<input type="checkbox" name="habit" value="travel">旅游
<inout type="checkbox" name="habit" value="音乐">音乐<br>
<input type="submit" text="提交">
</form>
EL表达式:
姓名:${param.name}
性别:${param.sex }
密码:${param.pwd }
年龄:${param.age }
爱好:${param.habit }
<hr>
${paramValue.habit[0] }
${paramValue.habit[1] }
${paramValue.habit[2] }
<hr>
过滤器:
<form action="LoginServlet" method="post">
用户:<input type="text" name="name">
密码:<input type="password" name="pwd">
<input type="submit" text="提交">
</form>
package com.servlet;
import java.io.*;
import java.util.HashMap;
import java.util.Map;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.*;
import com.bean.*;
public class LoginServlet extends HttpServlet{
protected void doPost(HttpServletRequest request,HttpServletResponse response)
throws ServletException,IOException{
String name= request.getParameter("name");
String pwd = request.getParameter("pwd");
Useruser user = new Useruser();
user.setUsername(name);
user.setPwd(pwd);
Map map = new HashMap();
map.put("aa", "bb");
map.put("cc", "dd");
map.put("ee", "ff");
Map epp = new HashMap();
epp.put("gg","hh");
epp.put("ii", "jj");
epp.put("kk", "ll");
request.getSession().setAttribute("epp", epp); //“epp”为下文${epp}的epp
//request.getSession().setAttribute("map", map);//不能用request.setAttribute ,session 为每个用户的状态,所以用session
request.getSession().setAttribute("user", user);
response.sendRedirect("success.jsp");
}
}
foreach标签:
<a href="ListUser.jsp" >当前在线人数</a>
Listuser.jsp:
<%@
taglib uri = "http://java.sun.com/jsp/jstl/core" prefix="c"
%>
<!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=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<c:forEach var = "mapmap" items="${epp}" > //此处的epp为上文的"epp",即为LoginServlet过滤器的epp,request即为页面跳转的数据,即为传到服务器端的数据
<c:out value="${mapmap.key} }"></c:out> //也能用EL表达式进行输出 ${mapmap.key} / ${mapmap[key]}
</c:forEach>
%>
</body>
</html>
以上是关于form表单+EL表达式+过滤器+foreach标签的主要内容,如果未能解决你的问题,请参考以下文章
Vue 将el-form数据,转换为json post 提交Spring Boot后台