一尘不染

如何在JSP中包含HTML?

jsp

我已经搜索了这个问题,有一些答案,但不完全是我的问题。所以这是我的jsp代码:

<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" %>

但是相反,我只想在“ else”块中包含“ loginForm.html”。我该怎么做?当然这是行不通的,但是您会猜到我想要什么:

<%
        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" ;
        }
    %>

阅读 382

收藏
2020-06-08

共1个答案

一尘不染

我想向您展示一种方法,请尝试以下方法。您可以尝试使用else代替if

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

</body>
2020-06-08