blog.co.uk  »  Next Blog  »    Create your own blog for free •   •  Flag this blog Login

File Uploading in JPDK Portlet on Oracle Portal Server

by extremeportal @ 26. Aug. 2006. - 10:43:48 pm

It has always been a topic of discussion about file uploading in portlet specially with JPDK portlet on Oracle Portal server.

I also faced some technical challenges while working with this but now come up with a solution and wants to share with portal world using this article.

You will find numerous post on OTN (Oracle Technology Network) regarding File upload in Portlet technology.
So finally I though about why not to write an article on my blog for the same.

And now...Here we go.......

1. Create a portlet application from your JDeveloper and just write a new servlet into any of your package. This servlet will be doing the actual file uploading functionality.

2. Make a entry for this servlet in your web.xml.

Sample code for the servlet entry in web.xml :-

<servlet>
<servlet-name>UploadFile</servlet-name>
<servlet-class>com.util.UploadServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>UploadFile</servlet-name>
<url-pattern>FileUploadServlet</url-pattern>
</servlet-mapping>

3. Let us say you will be having two JSP one is MyProfile.jsp and other is FileUpload.jsp. The FileUpload.jsp will be opened in a pop up window using window.open(<pass required parameters> ) once you click on a link from MyProfile.jsp.

(Note:- off course you might be having other Business and DB related classes and some other JSP also)

4. In the pop up window OR FileUpload.jsp , use the following as your form tag entry

<form method="post" action="<%=request.getContextPath()%>/FileUploadServlet" name="fileuploadform" enctype="multipart/form-data">

5. Once done with development and configuration , deploy your portlet application from the JDeveloper.

You can use application server connection from within your JDeveloper for deployment of your Portlet Application.

Let us understand complete scenario in a more practical way

Let us say you are creating a Matrimonial Portlet , where user will be entering his profile detail and will also upload his photograph.

Matrimonial Portlet must be having these minimum files as follows:

Two Java files , MatrimonialPortlet.java , FileUploadServlet.java and Two JSP files , UserProfile.jsp and FileUpload.jsp.

Again , some other files might be there for your DB and Business related operations.

Now the Functional approach will be like this

1. From MatrimonialPortlet.java , the UserProfile.jsp will be rendered. In this jsp user will enter his profile detail and at the end he will upload his photograph.

2. It means some where (On some link )on this UserProfile.jsp , you will call window.open(<pass required parameters> ) , which will result in opening FileUpload.jsp in a pop up window and this is the jsp where user will upload his photograph.

3. Once the photograph is uploaded , pop up window will be closed and user will come back to UserProfile.jsp and finally press the submit button for submitting his complete profile detail.

I hope , this article will help you to understand about File Uploading in JPDK portlet for Oracle Portal Server.

You can have a look on the thread called File Upload function in Portlet on OTN for the same.

Feel free to post your comment if you have any queries.



 
 

Trackback address for this post:

authimage

Comments, Trackbacks: Hide subcomments

George (HK) [Visitor]

09/29/06 @ 08:28

Hi author,

You are just fantastic to post this article which will save many hours of developers like me.

Thanks
George (HK)

Hari [Visitor]

10/22/07 @ 10:03

Hi extremeportal,

This article was too very helpful after the three days of struggle with file uploading on to the portal. You have done a fantastic job.
However, I had a requirement that, after the file uploading has been done it must return back to the same portal page and display a message.
For this, I have taken the URL of the portal page using "pRequest.getRenderContext().getPageURL()" and taken it on the UploadServlet. Now the problem that comes is, I am not able to use RequestDispatcher to go back to the page, but am able to response.sendRedirect.
Could you help me out in this regard. Also, I need to use RequestDispatcher to display the message on the page (i.e to put a message in the request).

Thanks,
Hari

Chid [Visitor]

11/20/07 @ 22:53

Hi All,

I am getting Error "Portlet could not be contacted"

My requirement is that I have to upload the file to the file share and then return back to the same jsp(portal) with the latest added attachment displayed as link.

Another thing is that I need to share the JPDK session with the servlet session. I need to access the JPDK session variables in the servlet. For this I used Resource Proxying of the servlet URL. Hence I am able to share the session.

I am also using pRequest.getRenderContext().getPageURL() to come back to the jsp.

My only issue is that randomly during upload I am getting Error "Portlet could not be contacted"

I dont have any clues on how to fix this issue. Sometimes upload works fine, sometimes it fails.

If i click browser back and then upload it uploads.

Does anybody come across this issue.

If so please let me know the same solution.

Thanks,
Chid

Leave a comment :

Your email address will not be displayed on this site.
Your URL will be displayed.
Allowed XHTML tags: <!, p, ul, ol, li, dl, dt, dd, address, blockquote, ins, del, a, span, bdo, br, em, strong, dfn, code, samp, kdb, var, cite, abbr, acronym, q, sub, sup, tt, i, b, big, small, img>
URLs, email, AIM and ICQs will be converted automatically.
Options:
 
(Line breaks become <br />)
(Set cookies for name, email & url)
Validation code:
Please enter the above code here:
For protection from spambots (case-sensitive).