我正在开发一个使用servlet(v3.0)和jetty v9的web服务器。我必须提供HTML页面,但在此之前,我需要根据布尔变量的值为页面上的几个元素修改CSS内联样式。如何将值从servlet传递到html页面
我一直在寻找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是否为此目的过度杀伤,如果是这样,是否有更好的选择?
http://stackoverflow.com/questions/54的可能的复制14600/pass-data-from-java-servlet-to-jsp – mkobit 2014-09-25 18:26:20