use OnClick with caution

JSP Code :

<a href="abc.jsp" onclick='’>LOGOUT

The above statement gets converted to Servlet CODE :


out.write("<a href=\"abc.jsp\" onclick='");

session.invalidate();

out.write("'>LOGOUT");


Conclusion:

What ever scriplet you write in onclick, will get executed every time the JSP is called. Not only on onclick as can be wrongly assumed.

About Vineet Verma

Developer/Blogger/Gamer/Lazy Couch Potato...:P Need PDF Books: Knowledge Base
This entry was posted in JSP, Servlet. Bookmark the permalink.

1 Response to use OnClick with caution

  1. Anonymous says:

    Yep yep yep, just figured it out, it's better to simply do a small doGet servlet with this code:

    request.getSession().invalidate();
    response.sendRedirect(“REDIRECT_URL”);

    I was trying the other way because I tought that making a sevlet just for logging out was ridiculous but here I am.

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s