i have a logout link in jsp and i call the logout function like this
function logout(){
document.getElementById("functiontype").value="logout";
document.forms["frmTempcard"].submit();
}
i call this like following : <li><a href="#" onclick="logout()">Logout</a></li>
when i click on the link i see the following url : http://localhost:8080/acct/notifier[the jsp file is there in this folder only ]/TempCardServlet
when i remove the folder name in url it is working fine. so how to redirect to desired servlet?
Please help me.
You should look at the
actionattribute of form, as per the code you have shared and the problem description, I feel you need to updateactionof your form.Currently you would have given
action='TempCardServlet'which means submit the request toTempCardServletresiding in the same URL as the current JSP page. This is relative path reference.When you specify
action='SomePath'then browser submits request tohttp://server/currenturl/SomePath. If the path to which you need to submit the request is not in current path then you need to either specify relative path or absolute path in following manner:Relative Path (in your case):
action='../TempCardServlet'– this method is not recommended as relative path might break your applicationAbsolute Path with Application context:
action='/acct/TempCardServlet'– this would refer to servlet on the same server, drawback of this is that you are hard-coding applicaiton context. To overcome this you can use Servlet API to get current application context and append it to your servlet path – you can also use standard tag libraries to get the context path appended.