RE: How to refer to a jsp page located in my portlet's /WEB-INF/jsp/ folder

infestationwatchSoftware and s/w Development

Oct 28, 2013 (3 years and 7 months ago)

74 views

Hello,



I'm trying to load one of my jsp file with ajax into a div.


How can I refer to my portlets jsp?


So far I have this, but the url is not good:

$(document).ready(function(){







$("a").click(function(){







$.ajax({















url:

"<%=renderResponse.encodeURL(renderRequest.getContextPath() +
"/WEB
-
INF/jsp/some.jsp")%>",















cache: false,















success: function(html){















$("#external").append(html);















}
















});













});










});


</script>

<div id="external">






</div>



some.jsp is located under my PORTLET's WEB
-
INF/jsp/


RE: How to refer to a jsp page located in my portlet's /WEB
-
INF/jsp/ folder

September 2, 2011 10:53 AM

Tomáš Polešovský

Rank: Expert

Posts: 418

Join Date: February 13, 2009

Recent Posts

Hello Zsolt,


you simply can't access files located in the WEB
-
INF directory using browser. It would be security bug



Better way is to use <portlet:resourceURL>. Using this tag you can create URL that will point to the
serveResource
method of your portlet. There you can check input parameters and use RequestDispatcher to include your JSP file.


--

tom


RE: How to refer to a jsp page located in my portlet's /WEB
-
INF/jsp/ folder

September 5, 2011 1:37 AM

Zsolt Vilhelm

Rank: New Member

Posts: 12

Join Date: August 30, 2011

Recent Posts

Could please provide me some examples or point me to the right direction?


RE: How to refer to a jsp page located in my
portlet's /WEB
-
INF/jsp/ folder

September 5, 2011 6:15 AM

Tomáš Polešovský

Rank: Expert

Posts: 418

Join Date: February 13, 2009

Recent Posts

Do you use MVCPortlet or have you created your own?


I assume you don't use MVCPortlet (where you can't include files from WEB
-
I
NF directory by default).


In the JSP file use:


$(document).ready(function(){







$("a").click(function(){







$.ajax({















url: "<portlet:resourceURL id="MyAjaxAction" />",















cache: false,















succ
ess: function(html){















$("#external").append(html);















}
















});













});










});


</script>

<div id="external">






</div>



In your portlet create serveResource method:






public v
oid serveResource(ResourceRequest request, ResourceResponse response)
throws Exception {







String id = request.getResourceID()







if ("MyAjaxAction".equals(id)) {










// do some code,










// e.g." request.setAttribute("dataToDi
splay", ...);











getPortletContext().getRequestDispatcher("/WEB
-
INF/jsp/some.jsp").include(request, response);







}





}



Hope it will work (haven't tried).


--

tom