by “jqgrid code”, I assume you mean the grid options. you can easily generate the JSON grid options from a servlet. Use any of the POJO-to-JSON libraries from http://www.json.org. On the JSP/HTML-side, use jQuery's AJAX function to retrieve the grid options from your servlet, then load them to your jqGrid.
example javascript:
$.get('url/of/servlet',function(options) {