Question

I am having a jsp page on which am trying to show a button depending on my variable flag.

If flag=0 then i want to have a submit ADD button but if flag is set to 1 then i want to have a disabled REQUEST SEND button and other button should not be shown while other is been shown.

Here is my jsp code part :

<%
   String groupidd = request.getSession().getAttribute("groupid").toString();
   s=null;
   rs=null;
   int flag=0;
   String sql="select * from TBGROUPUSERS where I_ID=? and GU_GROUPID=?";

    s = con.prepareStatement(sql);
    s.setString(1,idperson);
    s.setString(2,groupidd);
    rs=s.executeQuery();
    if(rs.next())
    flag=1;
   %>

Now based on this flag value how i can do this ?

Was it helpful?

Solution

You can add the flag to request after the if block -

request.setAttribute("flag", flag);

And later use the <c:choose> for conditional display -

<c:choose>
    <c:when test="${requestScope.flag == 1}">
        <!-- flag is 1 -->
    </c:when>
    <c:otherwise>
        <!-- flag isn't 1 -->
    </c:otherwise>
</c:choose>

Note: Scriplets in JSP is a bad practice. I strongly recommend that you read this answer.

OTHER TIPS

I am assuming you have a button like this in your html

///input type='submit' value='button' id='b1'///

in java script do some thing like this.

if(<%=flag == 0%>)
{
 document.getElementById('b1').value="add"
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top