简体   繁体   English

调用一个在加载时不从jsp返回任何信息的servlet

[英]calling a servlet which does not return anything…from a jsp while loading

I need to call a servlet during a page load(abc.jsp). 我需要在页面加载(abc.jsp)期间调用servlet。 The Servlet would not return anything.It just makes some updates to a database. Servlet不会返回任何东西,它只会对数据库进行一些更新。

If I use href to call the servlet, abc.jsp does not get loaded as the servlet does not return anything. 如果我使用href调用servlet,则不会加载abc.jsp,因为servlet不返回任何内容。

If I use form submit(empty form with no fields) to call the servlet and call it during onload event of the abc.jsp, that does makes a call to the servlet but abc.jsp will not be loaded. 如果我使用表单commit(无字段的空表单)来调用servlet,并在abc.jsp的onload事件期间调用它,则确实会调用servlet,但不会加载abc.jsp。

What is the best way to call the servlet which does not return anything and still load abc.jsp ? 调用不返回任何内容并仍然加载abc.jsp的servlet的最佳方法是什么?

Thanks 谢谢

Use jQuery Ajax request during page loade time: 在页面加载期间使用jQuery Ajax请求:

$(document).ready(function(){
    $.get( "myServlet" );
});

Maybe you should use Filter . 也许您应该使用Filter As Specification says: 如规范所述:

Filters differ from web components in that filters usually do not themselves create a response. 过滤器与Web组件的不同之处在于,过滤器本身通常不会创建响应。 Instead, a filter provides functionality that can be “attached” to any kind of web resource. 相反,过滤器提供的功能可以“附加”到任何种类的Web资源。 Consequently, a filter should not have any dependencies on a web resource for which it is acting as a filter; 因此,过滤器不应依赖于其充当过滤器的Web资源。 this way, it can be composed with more than one type of web resource. 这样,它可以由多种类型的Web资源组成。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM