Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个 java 类Main.java我正在计算变量中的和和差,比如
int sum = a+b; int diff = a-b;
a并且b是通过 Hibernate 来自数据库的值。现在我想在 JSP 上显示 sum 和 diff 值。请帮助我将 java 类Main.java中的 sum 和 diff 值带到 jsp。请给出 sum 示例代码。提前致谢。
a
b
在 Servlet / JSP 中实例化您的 Main.java
将它放在一个范围内:session或request
session
request
like request.setAttribute("myMain",main);
在 jsp usinh 中访问
Main myMain = (Main)request.getAttribute("myMain"); myMain.getSum()
如果你想使用 JSTL 路由
<c:out value="${myMain.sum}"/>