Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1073923
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T21:03:18+00:00 2026-05-16T21:03:18+00:00

Traditionally we have always used xml in the response which is parsed by a

  • 0

Traditionally we have always used xml in the response which is parsed by a Javascript method to execute post processes. I came up with a new, simpler implementation which uses a hidden input set by a requestAttribute and executed in an ajax callback.

JSP:

<%
    String jsPostProcess = (String)request.getAttribute("jsPostProcess");
    if (jsPostProcess!=null && jsPostProcess.trim().length()>0){        
%>
        <input type="hidden" id="jsPostProcess" name="jsPostProcess" 
            value="<%= jsPostProcess %> "/>
<%  } %>

AJAX CALLBACK:

var callback = {
    success: function(response) {
        var div = $(divId);
        if (div){
            div.innerHTML = response.responseText;              
        }
        var jsPostProcess = $('jsPostProcess');
        if (jsPostProcess)
            eval(jsPostProcess.value);
    },
    failure: function(response) {
        alert('Something went wrong!');
    }
}

SERVLET CODE:

request.setAttribute("jsPostProcess", jsPostProcess);

It works beautifully, and it is so much simpler for adding js post processes to virtually any call no matter how simple or complex the functionality is. No need for customized js methods for parsing.

Curious if anyone could identify any potential problems with it (such as security issues?) or make any suggestions for other alternatives. We currently use Prototype and YUI 2 on the front-end.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T21:03:20+00:00Added an answer on May 16, 2026 at 9:03 pm

    First, there’s no need for that unpleasant scriptlet code:

    <c:if test='${not empty jsPostProcess}'>
      <input type='hidden' id='jsPostProcess' name='jsPostProcess' value='${jsPostProcess}'>
    </c:if>
    

    Next thing is that I hope that somewhere before this point the “jsPostProcess” value has been scrubbed so that it doesn’t break the markup (like, in case it includes quotes).

    Just calling eval() on the value like that seems a little dangerous, though perhaps you know pretty well what it’s going to be.

    Finally I would offer the suggestion that as an alternative to that, if the “post process” code isn’t too big you could send it back in a response header. Then you wouldn’t have to drop any meaningless markup into your page.

    Oh, also finally: you might want to make the <input> be disabled. Or, alternatively, you don’t even have to use an input: you can use this trick:

    <script id='jsPostProcess' type='text/plain'>
      ${jsPostProcess}
    </script>
    

    Because the “type” attribute is “text/plain” the browsers won’t try to execute that code, and you can get the “text” of the <script> element whenever you want.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a product which has been traditionally shipped as an MSI file. It
I have a pretty common layout issue that I have traditionally used a table
I am starting a new Winforms application, and I've always used traditional ADO.NET methods
Traditionally, our plucky team of developers have always migrated our own reports into production.
Traditionally, when we use SQL string to done some work, we have to close
I have used traditional version control systems to maintain source code repositories on past
I traditionally deploy a set of web pages which allow for manual validation of
New to silverlight. Traditionally if I were to design a wizard-like process where a
I have traditionally implemented a Model-View-Presenter [Passive View] like so: interface IView { string
Traditionally, to call a JavaScript function once the page has loaded, you'd add an

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.