Naveen
Naveen

Reputation: 1243

How to display String variables recieved from a servlet into a form text field of JSP

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

Upvotes: 2

Views: 18516

Answers (3)

KV Prajapati
KV Prajapati

Reputation: 94653

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}"/>

Upvotes: 2

Ved
Ved

Reputation: 8777

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

Upvotes: 2

Mukesh Kumar
Mukesh Kumar

Reputation: 985

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

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

Upvotes: 0

Related Questions