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:
Your situation can be easily solved with the help of JSTL with EL:
If you have a more complex logic then it makes sense to create a custom tags.