0
votes

I have a main page with header, footer, left panel and main content. I want to dynamically change main content on click of left panel. For this I am using ajax call, ajax will call controller and controller will return jsp which I will replace in main content.

But the problem I am facing is that I am getting JSP properly if I am using purely html coding but if I use spring form it is not working.

Do I need to declared taglib in all jsp or only in Dashboard jsp.

  1. If I declare taglib in all child jsp then it not working and I do not declare then form:input do not render in to html

  2. Can we return jsp in ajax call to replace with main content because here it says only @ResponseBody (JSON) can be used in ajax call.

  3. I am using ajax call because I don't want to reload all my header, footer and left panel because they will always remain same.

Ajax code

<script type="text/javascript">
  $(".ldMainContent").click(function(){
    var actionName = this.id;
    actionName = "${pageContext.request.contextPath}/sadmin/forward/"+actionName;
         $.ajax({
            url:actionName,
            type:"POST",
            data:"URL",
            success:function(result){
            $("#mainContent").html(result);              
          }
       });  
   });
    
</script>

I am using bootstrap in design

1

1 Answers

3
votes

The content can be loaded using jQuery's load method.

The code will be

$(".ldMainContent").click(function(){
   var actionName = this.id;
   actionName = "${pageContext.request.contextPath}/sadmin/forward/"+actionName;
   $("#mainContent").load(actionName);  
})

In your controller don't have @ResponseBody it is used to return object as JSON or XML. The controller should return a view for the JSP page which should only have the content that you want inside the mainContent.

Do I need to declared taglib in all jsp or only in Dashboard jsp.

Yes you have to declare the taglibs which ever jsp file you are using the tags.