2

I have created a servlet that passes a string variable strname to a JSP page. The JSP recieves it into a variable "strname" using

request.getAttribute("strname") 

Now I want to display this inside the text field of a form

 <form action="LogoutServlet" method="post">
            <% String strname =(String)request.getAttribute("uname");%> 
            Username:<input type="text" name="username" value="${username}"/>
    </form>

but it is displaying "username" int the text field. How can I display the strname var in the text ?? Please Help

Hardik Mishra
  • 14,779
  • 9
  • 61
  • 96
Naveen
  • 1,193
  • 4
  • 13
  • 17

3 Answers3

2

You may use EL expression (read the FAQ).

<input type="text"
       value="${requestScope.strname}"/>

or

<input type="text"
       value="${strname}"/>

or

<input type="text"
       value="${param.username}"/>

or JSTL <c:out />

 <c:out value="${strname}"/>
Community
  • 1
  • 1
KV Prajapati
  • 93,659
  • 19
  • 148
  • 186
  • here is the entire form:
    <% String username = request.getAttribute("uname").toString();%> Username:
    – Naveen Apr 05 '12 at 06:58
2

Using $ you can get the value. For ex : <input type="text" name="strname" value="${strname}" /> (Assuming you are getting correct value in strname variable.)

Ved
  • 8,577
  • 7
  • 36
  • 69
0

You can use the jstl way to get the value stores in the request e.g

<input type="text" value="${uname}">

Mukesh Kumar
  • 945
  • 4
  • 11
  • 26