I have a servlet that forwards to a HTML page, using redirect. Because I am using ajax and php on the html page to do other functions. Can turn into a jsp. Is there a way I can get the name -"poNumber" I get in servlet in the session attributes. I was to get it and display it's value.
I am new to programming.
Can get this working in jsp.
However need to get this working in a html page. Can I do it with javascript?
I have tried:
<script type="text/javascript">
var purchaseOrderNo = session.getAttribrute("pONumb");
document.write("pONumb");
</script> [
This does not output any values on the HTML page.
Tried:
<script type="text/javascript">
var purchaseOrderNo = (String) session.getAttribrute("pONumb");
document.write("pONumb");
</script>
Again get no output on page.
Tried:
<script type="text/javascript">
String purchaseOrderNo = (String) session.getAttribrute("pONumb");
document.write("pONumb");
</script>
Again get no output on page?
Can not think of any thing else to try. The servlet that redirects to this HTML page creates and set session attribute pONumb.
No, you can't. JavaScript is executed on the client side (browser), while the session data is stored on the server.
However, you can expose session variables for JavaScript in several ways:
In JSP you'd have something like:
or:
Then in JS:
or:
The inline example is the most straightforward, but if you then want to store your JavaScript code as an external resource (the recommended way) it won't be feasible.
Below code may help you to achieve session attribution inside java script: