通过jsp url调用servlet中的函数
我正在尝试使用 jsp 文件 (index.jsp) 中的超链接对我调用 servlet(index.java) 的字段进行排序。 当用户单击标题(即“ID”)时,应从 servlet 调用 sort() 函数并进行排序。 附加信息:我从index.java中的数据库收集元素,并使用requestdispatcher对象将其打印在index.jsp页面上。
I'm trying to sort a field for which i call a servlet(index.java) using a hyperlink from my jsp file (index.jsp)..
When the user clicks the heading (which is "ID") the sort() function should be called from the servlet and should get sorted.
additional info: i collect the elements from the database in index.java and print it on the index.jsp page using the requestdispatcher object.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
据我所知,您不能直接从 JSP 调用 servlet 的方法。
您可以做的一件事是您可以调用一个 servlet,该 servlet 在其 service() 方法中为您进行排序并将相同的结构数据(但现在处于排序模式)返回到 JSP。
您可以使用 AJAX(仅刷新该页面的一部分)或刷新整个页面来调用此方法。
According to me you can not call a method of the servlet directly from the JSP.
One thing you can do is you can call a servlet which in its service() method do the sorting for you and returns the same structure data (but now in sorted mode) to the JSP.
You can call this using AJAX (which refreshes the part of that page only) or by refreshing the the whole page.