0

I've a variable in jsp which has been passed from servlet. Now I want fetch the value of that variable in Jquery function

Here is my servlet:

request.setAttribute("bt", list);
request.setAttribute("rep", docbase);
request.getRequestDispatcher("Welcome.jsp").forward(request, response);

Here is my jsp where I'm retrieving the variable:

<%String repository = (String)request.getAttribute("rep"); %>

Here is my jQuery where I want to fetch the value of "repository":

<script type="text/javascript">
        $(document).ready(function() {
          var name = $('select[name="doctype"]').attr('id');
          alert($.name);
            $.ajax({
             url:'',
             type:'post',
             cache:false,
             success: function(response){


             }
            });

        });


        </script>

I'm very new to jQuery, any kind of help is appreciated. Thank you!

Zeus07
  • 168
  • 1
  • 5
  • 17
  • 1
    you can write a code something like this. But it's not a clean way of doing it. Why do you want to do it? You can do it via AJAX calls. Here is the sample code var myVariable = <%=request.getAttribute("rep");%> – Hitesh Kumar Jun 14 '17 at 12:14
  • @user2531799 I know use of scriptlets is very much discouraged but I'm very new to JSTL and EL. Can you provide any link where I can look into? – Zeus07 Jun 14 '17 at 12:20
  • 1
    You can do var myVariable = '${RequestAttributeVariable}'; that is in above example I have used rep, So the actual implementation will be var myVariable = '${rep}'; Remember to use single quotes and then your JSTL code or EL code – Hitesh Kumar Jun 14 '17 at 14:48

0 Answers0