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

3 Answers 3

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.)

Sign up to request clarification or add additional context in comments.

2 Comments

<% String username =(String)request.getAttribute("strname");%> Username: <input type="text" name="username" value="${username}" /> NOT WORKING
Use this :- <%=request.getAttribute("whatevername")%>
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}"/>

1 Comment

here is the entire form: <form action="LogoutServlet" method="post"> <% String username = request.getAttribute("uname").toString();%> Username: <input type="text" name="username" value="${username}" readonly="readonly" /> </form>
0

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

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.