码迷,mamicode.com
首页 > 其他好文 > 详细

form表单+EL表达式+过滤器+foreach标签

时间:2020-03-04 19:31:18      阅读:83      评论:0      收藏:0      [点我收藏+]

标签:tag   ted   setattr   list   except   htm   ring   insert   reac   

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标签

标签:tag   ted   setattr   list   except   htm   ring   insert   reac   

原文地址:https://www.cnblogs.com/broadencoder/p/12411283.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!