action 里设置一个值,如何在jsp页面上用el表达式显示出来

2024-11-16 03:26:38
推荐回答(2个)
回答(1):

要放到 request或者session中

方法1:request.setAttribute("a",a); //推荐此方法
方法2:session.setAttribute("a",a); //该方法一般用于存储用户的登录信息

页面上就是 ${a}

回答(2):

action里面的值在jsp页面可以这么用el表达式获取:

action代码:
public void doPost(HttpServletRequest request , HttpServletResponse response) throws ServletException, IOException
{
request.setCharacterEncoding("UTF-8");
Map m = request.getParameterMap() ;
for(String name : m.keySet())
{
System.out.println(name + ":" + m.get(name)[0]) ;
request.getSession().setAttribute(name, m.get(name)[0]);
}

request.getRequestDispatcher("theEnd.jsp").forward(request, response);
}

jsp页面取值方式:

${name}=${sessionScope[name]}