【发布时间】:2014-11-20 15:03:05
【问题描述】:
我正在使用 servlet (v3.0) 和 jetty v9 开发 Web 服务器。我必须提供一个 HTML 页面,但在此之前,我需要根据布尔变量的值修改页面上几个元素的 CSS 内联样式。
多年来,我一直在查看 JSP 教程和示例,但我觉得自己离弄明白还差得远。为了简化它,这就是我想要做的:
page.jsp:(在 /WAR/html 中)
<html>
<head>My Page</head>
<body>
<p <% style="display:none" if variable is true %>></p>
</body>
</html>
GetPage.java:
public class GetPage extends HttpServlet {
public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {
boolean decision = getDecision();
// get the JSP page and process the JSP with the boolean variable...
resp.setContentType("text/html");
resp.getWriter().print(???);
}
}
我已经使用 Java 多年,但以前从未使用过 JSP。我原以为这是 JSP 101,但我不明白它是如何工作的。此外,我的真实用例与上面的示例相差不远。 JSP 是否为此目的而矫枉过正,如果是,是否有更好的选择?
【问题讨论】: