0

I want to retrieve the request scope attribute in javascript as follows. How can I achieve this?

function caseChanges(req) {
    var innervalue= "${dashboardTicketSummary}"
    alert("nand you are 1234");
    alert(innervalue);
} 

2 Answers 2

1

Assumin the javascript is included inline on the jsp page -- you're on the right track, you just need to make sure the attribute is set (typically by your controller class) on the HttpServletRequest object, ie:

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse res)
{
  DashboardTicketSummary dts = ...; // code to obtain ticket summary here

  req.setAttribute("dashboardTicketSummary", dts);

  // code to dispatch to your jsp page here
}

Of course there are many other more sophisticated way -- especially is you use popular MVC framework such as Spring

Sign up to request clarification or add additional context in comments.

2 Comments

i am setting it in an action class , i am having issue pulling the value on a jsp page in java script.
Sorry, My Bad. It was a ajax call.
0

set value to request attributes and write this piece of code in a script tag on jsp page (like index.jsp):

<script>
    function caseChanges(req){
        var innervalue= "${dashboardTicketSummary}"
        alert("nand you are 1234");
        alert(innervalue);
    } 
</script>

for better maintainability, you can gathering all attributes to a global object on jsp, and refer to it on other js files:

index.jsp

<script>
    var REQUEST_ATTRS = {
            dashboardTicketSummary : '${dashboardTicketSummary}',
            otherAttributes :'${otherAttributes}'
        };
</script>

other.js

function caseChanges(req){
    var innervalue= REQUEST_ATTRS.dashboardTicketSummary ;
    alert("nand you are 1234");
    alert(innervalue);
} 

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.