EL表达式未在JSP中评估

时间:2015-10-07 09:40:33

标签: jsp servlets el

我有简单的servlet将参数传递给jsp文件。 这是代码:

String userName = request.getParameter("userName");
    HttpSession session = request.getSession();
    session.setAttribute("userName", userName);
    request.getRequestDispatcher("welcome.jsp").forward(request, response);

页面welcome.jsp包含:

<body>
<h3 align="center">Welcome ${userName}!!!</h3>

<a href="index.jsp">go back</a>
</body>

index.jsp:

<form method="post" action="check">
Name <input type="text" name="userName" >
<input type="submit" value="submit">
</form>

最后是web.xml:

<servlet>
    <servlet-name>check</servlet-name>
    <display-name>check</display-name>
    <description></description>
    <servlet-class>MyServlet</servlet-class>
</servlet>
<servlet-mapping>
    <servlet-name>check</servlet-name>
    <url-pattern>/check</url-pattern>
</servlet-mapping>

问题是该参数未传递给welcome.jsp。我还是看

  

$ USERNAME

有什么问题?请帮帮我。

1 个答案:

答案 0 :(得分:-1)

你可以做到 <h3 align="center">Welcome <%=(String)session.getAttribute("userName")%>!!!</h3>代替 <h3 align="center">Welcome ${userName}!!!</h3>