将数据从 java 类填充到 jsp 中
如何将 java 类(不是 servlet)中的数据填充到 jsp 页面上。 一种方法是 jsp<->servlet<->java 类...
是否有一种不使用 servlet..jsp<->java 类的直接方法?
How to populate the data from a java class(not a servlet) onto a jsp page.
One way would be jsp<->servlet<->java class....
Is there a direct way without using servlet..jsp<->java class??
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以通过将 jar 放入 web 应用程序的 libs 文件夹中(如果您还没有这样做)然后将其导入到您的 jsp 中,将您的类导入到 jsp 中:
完成后,您可以在 jsp 中使用您的类像平常一样:
另一种总体上更可取的方法是创建一个使用您的类的 TagLibrary。与在 jsp 中使用 Java 代码相比,TagLibraries 更清晰、更易于支持和理解。 Sun 的使用和创建标签库的指南非常好:
http://java.sun.com/products/jsp/tutorial/TagLibraries3.html
You could import your class into the jsp by dropping the jar into the libs folder for the webapp (if you haven't done so already) then importing in into your jsp:
Once you've done so you can use your class in the jsp as you normally would:
Another way which would be preferable overall is to create a TagLibrary that uses your class. TagLibraries are cleaner and easier to support and understand than using Java code inside your jsp. Sun's guide to using and creating tag libraries is pretty good:
http://java.sun.com/products/jsp/tutorial/TagLibraries3.html
它是呈现 jsp 页面的 servlet 容器。将数据传递到 jsp 的唯一方法(可能有一个例外)是在 HttpServletRequest(请求范围)、HttpSession(会话范围)或 ServletContext 本身(应用程序范围)上设置属性。所以你的问题的简短答案是否定的。
也就是说,我可以想到其他一些可能性,让其他类将数据获取到 jsp(或者至少将其呈现在页面上):
希望这有帮助。顺便说一句,如果您对您想要完成的任务进行更详细的解释,将会有所帮助。
It's the servlet container that renders the jsp page. The only way (with one possible exception) to pass data to a jsp is by setting attributes on the HttpServletRequest (request scope), HttpSession (session scope), or the ServletContext itself (application scope). So the short answer to your question is no.
That said, there are a few other possibilities I can think of to have other classes get data to a jsp (or at least get it rendered on the page):
Hope this helps. Btw, it would help if you put a little more detailed explanation of what you are trying to accomplish.