Thread: File Upload function in Portlet.


Permlink Replies: 22 - Pages: 2 [ 1 2 | Next ] - Last Post: May 6, 2008 11:08 PM Last Post By: user619120
georgelkh

Posts: 146
Registered: 07/20/01
File Upload function in Portlet.
Posted: Aug 21, 2006 12:41 AM
Click to report abuse...   Click to reply to this thread Reply
Dear all,

I understanded that there are already many discussions on the issues of file upload function on Portal. But, it seems that there is no a comfortable answer.

My question is that I want to use JDeveloper to develop a portlet for uploading file to DB table.

To my understand, I may need to write a servlet to handle the actual file upload process, am I right ?

Thanks a lot.
George (HK)
Try_Catch_Final...

Posts: 164
Registered: 11/21/05
Re: File Upload function in Portlet.
Posted: Aug 22, 2006 10:23 PM   in response to: georgelkh in response to: georgelkh
Click to report abuse...   Click to reply to this thread Reply
Hi George ,

Yes you are right that we need to introduce a servlet into our portlet application for file uploading functionality.

The scenario will be like this.

1. Click on a Upload File button.

2. A Pop up window will be opened. The pop up window will be having the browse button to select the file from your file system.

3. On submitting of that form ( pop up window ) a servlet will be triggered which will be responsible for file uploading and then the pop up window will be closed.

4. Now you are back to parent window , from where you clicked on the Upload file button in step 1.

5. You can proceed with the parent form fields details if you have any.

The File uploading task will be done in step 3 only.

Hope this will help you.

Thanks

<Neeraj Sidhaye/>
Try_Catch_Finally AT YAHOO DO COM
ChkOut_ChkIn AT YAHOO DOT CO DOT IN

http://ExtremePortal.blog.co.uk
georgelkh

Posts: 146
Registered: 07/20/01
Re: File Upload function in Portlet.
Posted: Aug 22, 2006 11:42 PM   in response to: georgelkh in response to: georgelkh
Click to report abuse...   Click to reply to this thread Reply
Hi Neeraj Sidhaye,

thanks a lot.

In addition, I am developing a servlet for file upload with JDeveloper.
When I completed the development, how can I deploy it to Oracle Portal?

Use the standard method of deployment in JDeveloper ?

Also, in my file upload portlet, how can I make the form action to point to the servlet ?

Thanks
George (HK)
Try_Catch_Final...

Posts: 164
Registered: 11/21/05
Re: File Upload function in Portlet.
Posted: Aug 23, 2006 12:14 AM   in response to: georgelkh in response to: georgelkh
Click to report abuse...   Click to reply to this thread Reply
Hi George,

Here is the solution for your queries :-

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

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

Sample code for the servlet entry :-

<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. Now , in the pop up window OR FileUpload.jsp , use the following as your form tag

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

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

5. I am assuming that you have created a new application server connection from within your JDeveloper and you are using this connection for deployment of you portlet application.

I hope , the above steps will help you to go ahead.

Thnx

<Neeraj Sidhaye/>

http://ExtremePortal.blog.co.uk

georgelkh

Posts: 146
Registered: 07/20/01
Re: File Upload function in Portlet.
Posted: Aug 23, 2006 1:57 AM   in response to: georgelkh in response to: georgelkh
Click to report abuse...   Click to reply to this thread Reply
Hi Neeraj Sidhaye,

Your explanation is just crystal clear.

I will try it out now.

Thanks very much.
George (HK)
georgelkh

Posts: 146
Registered: 07/20/01
Re: File Upload function in Portlet.
Posted: Aug 23, 2006 3:11 AM   in response to: georgelkh in response to: georgelkh
Click to report abuse...   Click to reply to this thread Reply
Hi,

I set the <servlet> and <servlet-mapping> as you mentioned.

Then, I deployed the portlet which set the form action pointing to the servlet.

On the webpage, I press [Submit] button and the result is HTTP 405 error.

I need to refresh the page again in order to call the servlet successfully.

Any suggestion?

thanks
George (HK)
Try_Catch_Final...

Posts: 164
Registered: 11/21/05
Re: File Upload function in Portlet.
Posted: Aug 23, 2006 4:59 AM   in response to: georgelkh in response to: georgelkh
Click to report abuse...   Click to reply to this thread Reply
Hi George ,

A couple of quick questions :-

1. Did you able to open the poup window and once submitting from that window , is your servlet is triggering ?

2. On the Webpage , i press submit button , i didn't get this line.
Are you talking about the submit button of the popup window ?

Thnx

<Neeraj Sidhaye/>

http://ExtremePortal.blog.co.uk

georgelkh

Posts: 146
Registered: 07/20/01
Re: File Upload function in Portlet.
Posted: Aug 23, 2006 7:42 PM   in response to: georgelkh in response to: georgelkh
Click to report abuse...   Click to reply to this thread Reply
Hi Neeraj Sidhaye,

1. Did you able to open the poup window and once submitting from that
window
Yes, I put the "file upload" portlet on a separate page.
And use the Portal buildin [URL] building block to open the portlet in a new window.

For testing whether my servlet got triggered or not, I just create a simple servlet for testing purpose as following:
**********************************************************************************************
package mypackage6;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.PrintWriter;
import java.io.IOException;

public class Servlet1 extends HttpServlet
{
private static final String CONTENT_TYPE = "text/html; charset=Big5";

public void init(ServletConfig config) throws ServletException
{
super.init(config);
}

public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
response.setContentType(CONTENT_TYPE);
PrintWriter out = response.getWriter();
out.println("<html>");
out.println("<head><title>Servlet1</title></head>");
out.println("<body>");
out.println("The servlet has received a GET. This is the reply.");
out.println("</body></html>");
out.close();
}
}
**********************************************************************************************

For the web.xml configuration file, I add the following:
**********************************************************************************************
<servlet>
<servlet-name>Servlet1</servlet-name>
<servlet-class>mypackage6.Servlet1</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Servlet1</servlet-name>
<url-pattern>FileUploadServlet</url-pattern>
</servlet-mapping>
**********************************************************************************************

For the form, my coding is as following:
**********************************************************************************************
<%@page contentType="text/html; charset=Big5"
import="javax.naming.*"
import="javax.sql.*"
import="java.sql.*"
import="oracle.jdbc.*"
import="java.sql.Date"
import="java.util., oracle.portal.provider.v2."
import="oracle.portal.provider.v2.http.HttpCommonConstants"
import="oracle.portal.provider.v2.render.PortletRendererUtil"
import="oracle.portal.provider.v2.render.PortletRenderRequest"
import="oracle.portal.provider.v2.render.http.HttpPortletRendererUtil"
import="oracle.portal.provider.v2.url.UrlUtils"
%>

<body>
<form name="form_name" method= "POST" action="<%=request.getContextPath()%>/FileUploadServlet"
enctype="multipart/form-data">
<input type="text" name="textline" size="30">
<input type="file" name="datafile" size="40">
<input type="submit" value="Send">
</form>
</body>
**********************************************************************************************

is your servlet is triggering ?
Yes, my servlet got triggered when I refresh the "file upload" window, but not the first time I press [Submit] button on the "file upload" window.

Any idea ?

thanks
George (HK)
Try_Catch_Final...

Posts: 164
Registered: 11/21/05
Re: File Upload function in Portlet.
Posted: Aug 23, 2006 10:40 PM   in response to: georgelkh in response to: georgelkh
Click to report abuse...   Click to reply to this thread Reply
Hi George ,

See , you are saying that " I put the "file upload" portlet on a separate page and And use the Portal buildin [URL] building block to open the portlet in a new window."

Here we won't open portlet in a new window. we will just use the window.open(<pass required parameters>) to open a pop up window. This will be a your say FileUpload.jsp.

Let me clear you the complete scenario in a more practical way

Let's say you are making a Matrimonial portlet :-) .. where user will be entering his profile detail and will also upload his photograph.

Matrimonial Portlet is having the following fiels

2 java files , MatrimonialPortlet.java , FileUploadServlet.java and
2 jsp's files , UserProfile.jsp and FileUpload.jsp.

Some other files will also be there for your DB and Business related operations.

Now you write the code like this ,

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.

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

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.


I hope this practical scenario will help you to understand in a better way.

Feel free to ask if you have any doubts.

Thnx
<Neeraj Sidhaye/>

http://ExtremePortal.blog.co.uk

user537696

Posts: 11
Registered: 10/19/06
Re: File Upload function in Portlet.
Posted: Oct 19, 2006 9:01 AM   in response to: Try_Catch_Final... in response to: Try_Catch_Final...
Click to report abuse...   Click to reply to this thread Reply
Hi Neeraj,

I also wanted to implement the same file upload functionality on the Oracle portal and thanks to your thread and blog I managed to get it done upto some extent.

I have upload.jsp file which contains the file field with the browse button to upload a file. When this file submits, it makes a call to UploadServlet. My problem is I can't access any post variable using request.getParameter ("name"). I am getting null value when I retrieve it from the servlet.

More to the point, I have a hidden variable called "name" on the upload.jsp page. I cant access this variable from the servlet as follows. I am getting null value. But when I check the source of upload.jsp, I can see the value of name variable. It's just not accessible from the servlet.

request.getParameter ("name").

can you be any of help ?

TIA

Seevali
Try_Catch_Final...

Posts: 164
Registered: 11/21/05
Re: File Upload function in Portlet.
Posted: Oct 19, 2006 11:50 AM   in response to: user537696 in response to: user537696
Click to report abuse...   Click to reply to this thread Reply
Hi Seevali ,

When you perform a multipart/form-data upload, your request is not the same as normal form submission. You need to call request.getInputStream() to process your parameters and files and hence you can't access your form parameters with simple request.getParameter('<name>');

there are so many utilities which can be make use of getting the form parameters in case of multipart/form-data, one of them is here below which you can use.

1) just visit javazoom.com, then download latest version for upload the files.

2) Extract the zip & thay giving four jar files
they are:

i)uploadbean.jar
ii)struts.jar
iii)fileupload.jar
iv)cos.jar

3) put the jar files to your WEB-INF/lib folder and set the class path.

just use import javazoom.upload.*; into your servlet code and make use of the available methods to retrieve the form parameters.

hope this will help u...and welcome for any further queries.

Thanks

<Neeraj Sidhaye/>

http://ExtremePortal.blog.co.uk
georgelkh

Posts: 146
Registered: 07/20/01
Re: File Upload function in Portlet.
Posted: Oct 19, 2006 7:00 PM   in response to: Try_Catch_Final... in response to: Try_Catch_Final...
Click to report abuse...   Click to reply to this thread Reply
hi <Neeraj Sidhaye/>,

In your last reply, you mentioned

3) put the jar files to your WEB-INF/lib folder and set the class path.

My situation is that I don't understand how to add the 4 jar files into my FileUpload project in JDeveloper. I just use the "Just to Project ..." function in JDeveloper to add those 4 jar files.

just use import javazoom.upload.*; into your servlet code and make use of the available methods to retrieve the form parameters.

I added the line import javazoom.upload.*; into my servlet and it compiles with no problem.

But, if I modified the jsp file as

<%@page contentType="text/html; charset=Big5"
import="oracle.portal.provider.v2.render.PortletRenderRequest"
import="oracle.portal.provider.v2.http.HttpCommonConstants"
import="java.util.*"
import="javazoom.upload.*"
%>

<%
PortletRenderRequest pReq = (PortletRenderRequest)
request.getAttribute(HttpCommonConstants.PORTLET_RENDER_REQUEST);
%>

<jsp:useBean id="upBean" scope="application" class="javazoom.upload.UploadBean">
<%
Properties props = new Properties();
props.put("user","apps");
props.put("password","apps");
upBean.setDatabasestore("oracle.jdbc.driver.OracleDriver",
"jdbc:oracle:thin:@erp01:1521:prod", props);
%>
</jsp:useBean>

And run on Portal, error is reported in log file that the class javazoom.upload.UploadBean is not found.

thanks
George (HK)
user537696

Posts: 11
Registered: 10/19/06
Re: File Upload function in Portlet.
Posted: Oct 20, 2006 1:00 AM   in response to: Try_Catch_Final... in response to: Try_Catch_Final...
Click to report abuse...   Click to reply to this thread Reply
Hi Neeraj,

Thanks for the quick reply. I have used Apache Commons File Upload package for file uploading. I have done this before and I have forgot it completely. But your reply reminds me what to do.

I had to access these variable within the isFormField if clause. Somwhow I managed to get this done.

Thanks again for you r help.

Seevali
user537696

Posts: 11
Registered: 10/19/06
Re: File Upload function in Portlet.
Posted: Nov 6, 2006 3:39 AM   in response to: Try_Catch_Final... in response to: Try_Catch_Final...
Click to report abuse...   Click to reply to this thread Reply
Hi Neeraj,
I am coming back to you again after a sometime. I have done the file uploading application succeffully and everything is working fine.

But I have got an issue.
When a user uploads a file, it saves the files into a directory called uploadFiles with in the htdocs directory.

Eg: ...../htdocs/uploadFiles/

If this directory is not exist, I will create the directory including any subdirectories using file.mkdirs ().

My issue is, whenever I redeploy the application to Oracle AS, it deletes the existing files and the directory on the server. Then it starts as a fresh application and creates the directory again and strore the file.

This should not happened whenever I redeploy the application.

Have you got any idea about this issue pls ?

TIA
Seevail
Try_Catch_Final...

Posts: 164
Registered: 11/21/05
Re: File Upload function in Portlet.
Posted: Nov 7, 2006 11:34 PM   in response to: user537696 in response to: user537696
Click to report abuse...   Click to reply to this thread Reply
Hi Seevail,

actually what is happening in your case is, you are creating a uploadFiles directory at run time and uploading files into this folder. right ?

so , whenever you redeploy you application your project won't have this directory and off course it will delete all the files and hence directory also.

I think what you could do is, just put a temp file into your htdocs/uploadFiles/temp.txt and it should be into your jdeveloper project.

so whenever next time you will deploy your application, it will always have a folder with a temp file. Also in this case you need not to apply the check for "if dir exists then call file.mkdir()..."

let me know your comments on this....

Thanks

<Neeraj Sidhaye/>
Try_Catch_Finally AT YAHOO DOT COM


http://ExtremePortal.blog.co.uk
Legend
Guru Guru : 2500 - 1000000 pts
Expert Expert : 1000 - 2499 pts
Pro Pro : 500 - 999 pts
Journeyman Journeyman : 200 - 499 pts
Newbie Newbie : 0 - 199 pts
Oracle ACE Director
Oracle ACE Member
Oracle Employee ACE
Helpful Answer (5 pts)
Correct Answer (10 pts)

Point your RSS reader here for a feed of the latest messages in all forums