Search code examples
javahtmljspjakarta-ee

JSP text field read only


Please tell me how to make JSP text filed read only using JSP ? In html we can use

<input type = "text" name="someName" readonly/>

But how can we do the same thing using JSP.(If I want to disable text field based on user account type?)


Solution

  • Add the readOnlyattribute according to parameter, for example

    String readOnly = "CAN_READ".equals(request.getParameter("userAccountType")) ? "readOnly" : "";
    

    And use it in input:

    <input type = "text" name="someName"<%=readOnly%> />