如何在JSP中包含HTML?

我已经搜索了这个问题,有一些答案,但不完全是我的问题。所以这是我的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" ;

}

%>

回答:

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

<body>

<%

int x = 10;

if(x>10) {

%>

<%@include file="some.html" %>

<%

}

%>

</body>

以上是 如何在JSP中包含HTML? 的全部内容, 来源链接: utcz.com/qa/401846.html

回到顶部