Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I share session attributes between a servlet and jsp file?
    primarykey
    data
    text
    <p>I have a form which when submitted stores data from it's fields to the database. The action forward in the struts-config maps back to the same page on Success/Failure of data insertion into the database. I would like to alert the user once this is successfully completed, so I set a session attribute(i.e. success/failure) in the method of the action class for the form. I then get and print out this session attribute once the jsp page has been accessed again.</p> <p>So far I have done this in the Action Class:</p> <pre><code> public static void setJavaScriptNotification(HttpServletRequest request, String notificationText) { HttpSession session = request.getSession(true); session.setAttribute("notification_javascript", notificationText); } </code></pre> <p>And in the jsp file that contains the form I have:</p> <pre><code> &lt;% String notificationJavaScript = (String) request.getSession().getAttribute("notification_javascript"); pageContext.setAttribute("notification_javascript", notificationJavaScript); request.getSession().removeAttribute("notification_javascript"); %&gt; &lt;html&gt; &lt;head&gt; &lt;logic:present name="notification_javascript"&gt; &lt;script type="text/javascript" language="JavaScript"&gt; function showAlerts() { alert("&lt;bean:write name="notification_javascript"/&gt;"); } &lt;/script&gt; &lt;/logic:present&gt; &lt;/head&gt; &lt;body onload="doPreOnload(); showAlerts();"&gt; </code></pre> <p>When I print out the session attributes in the jsp, I can't find the notification_javascript attribute. I'm new to HTTP, so I could be doing something wrong there.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload