Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to include HTML in JSP?

Tags:

java

html

jsp

I've searched for this question, there are some answers, but not exactly as my question. So, here is my jsp code:

<body>
    <%
        if (manager.isValid(request.getParameter("username"),request.getParameter("password"))){
            out.print("<h1> Welcome ");
            out.print(request.getParameter("username") + "</h1>");
        } else {
            out.print("<h1> Please Try Again </h1> <br />");
            out.print("Either your username or password is incorrect. Please Try again <br /> <br />");
                        }
    %>
    <%@ include file="LoginForm.html" %>
    

but instead of this, I want to include "loginForm.html" only in "else" block. How can I do it? Of course this doesn't work, but you'll guess what I want:

<%
        if (manager.isValid(request.getParameter("username"),request.getParameter("password"))){
            out.print("<h1> Welcome ");
            out.print(request.getParameter("username") + "</h1>");
        } else {
            out.print("<h1> Please Try Again </h1> <br />");
            out.print("Either your username or password is incorrect. Please Try again <br /> <br />");
            include file="LoginForm.html" ;
        }
    %>
like image 747
Giorgi Margiani Avatar asked May 04 '13 16:05

Giorgi Margiani


1 Answers

I would like to show you a way, try like below. You can try with else instead with if.

<body>
        <%
            int x = 10;
            if(x>10) {
        %>
        <%@include  file="some.html" %>
        <%
            }
        %>

</body>
like image 95
Vinay Avatar answered Sep 28 '22 06:09

Vinay