So I have been wandering around the web for some time looking for this answer. Is there no way of having text fields in java scriptlets for a JSP? I know that in C# you can have
@Html.TextField();
And that will create a text field for you to use as C# code.
Why I would like this, is that I am grabbing a session and checking to see if the user attribute has a user name stored. If it does I don't want it to display the username textbox. Although from what I can tell I can't do that with java scriptlets.
<%if(session.getAttribute("user") == null) %>
Username: <input type="text" name="name"><br/>
Is there something that I am missing?
This will work, but it's better to use JavaServer Pages Standard Tag Library and Expression language
instead of scriptlets. It tend to complicate maintenance for JSP-pages.
You can set a scoped variable on the JSP page. In this manner:
<c:set var="myVariable" scope="page" value="expression"/>
Your situation can be easily solved with the help of JSTL with EL:
<c:if test="${sessionScope.user eq null}">
<c:out value="Username: ${myVariable}" />
</c:if>
If you have a more complex logic then it makes sense to create a custom tags .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.