1

I have simple servlet that passes parameter to jsp file. Here is the code:

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

The page welcome.jsp contains:

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

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

The index.jsp:

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

Finally 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>

Problem is that parameter is not passed to welcome.jsp. I still see

$userName

What is the problem? Please help me.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Michal
  • 610
  • 10
  • 24

1 Answers1

-1

You can do <h3 align="center">Welcome <%=(String)session.getAttribute("userName")%>!!!</h3> instead of <h3 align="center">Welcome ${userName}!!!</h3>

nubteens
  • 5,462
  • 4
  • 20
  • 31