• Post Reply Bookmark Topic Watch Topic
  • New Topic

Accessing session using hyperlink rather than submit button inside a JSP  RSS feed

 
Denis St-Amour
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am looking to convert a logout button inside a jsp page to a hyperlink. Is there a way to access the session using a hyperlink instead of a form? Here is what I'm trying to convert:


<form method="POST" action="myservlet">
<input type="hidden" name="requestPageName" value="<%= REQUEST_PAGE_NAME %>">
<input type="hidden" name="actionCode" value="<%= ActionConstants.NMME_LOGOFF %>">
<input type="submit" value="Logoff">
</form>

TO:

<% if (appSession.getActionCode() == ActionConstants.ULGN_LOGON) {%>
<li id="cn-cmb6"><a href="<%=APP.JSP_PATH%>login.jsp"><fmt:message key="logout" bundle="${fmtCommonMenuBar}"/></a></li>
<%}else { %>
<li id="cn-cmb6"><a href="#"></a></li>
<%}%>


As you can see I am also using bundles, so I can't use session.invalidate() because my language toggle would no longer work once I return to the login page.



 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66149
146
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not sure what you mean by "access a session". Forms and links submit requests, not "access sessions".

Perhaps you can explain a bit more about what you are trying to accomplish.

Also, Java code (scriptlets) in a JSP is a practice that has been discredited for a almost a decade now. It's long passed the time to use more modern techniques such as the JSTL and EL.
 
Denis St-Amour
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What I'm trying to figure out is how to pass the actionCode value to 'myservlet' through a url instead of a form.


This is a very old application and we are in the process of trying to eliminating as much Java code in the JSPs. The code provided has not yet been converted fully.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66149
146
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can set the form method to "get", and submit the form under script control when the link is clicked.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!