Npa
Npa

Reputation: 617

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). The Servlet would not return anything.It just makes some updates to a database.

If I use href to call the servlet, abc.jsp does not get loaded as the servlet does not return anything.

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.

What is the best way to call the servlet which does not return anything and still load abc.jsp ?

Thanks

Upvotes: 0

Views: 258

Answers (2)

Sas
Sas

Reputation: 2503

Use jQuery Ajax request during page loade time:

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

Upvotes: 1

Szarpul
Szarpul

Reputation: 1571

Maybe you should use Filter. As Specification says:

Filters differ from web components in that filters usually do not themselves create a response. Instead, a filter provides functionality that can be “attached” to any kind of web resource. Consequently, a filter should not have any dependencies on a web resource for which it is acting as a filter; this way, it can be composed with more than one type of web resource.

Upvotes: 0

Related Questions