How to handle exception on File Upload in stripes.

View: New views
3 Messages — Rating Filter:   Alert me  

How to handle exception on File Upload in stripes.

by Tissen Sebastian :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hello,
 
I have a file upload functionality in my application. The validation on the File size works fine in actionbean if I upload a file which is less than 10mb in size.
 
My issue is, Stripes throws an Exception if my file size is greater than 10mb. I need to show a message back to user on the form if this exception occured.
 
Could anybody suggest a way to handle this exception (not using commong Error page)?

--
Cheers,
Tissen Sebastian

-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php
_______________________________________________
Stripes-users mailing list
Stripes-users@...
https://lists.sourceforge.net/lists/listinfo/stripes-users

Re: How to handle exception on File Upload in stripes.

by Alan Burlison :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Tissen wrote:

> Could anybody suggest a way to handle this exception (not using
> commong Error page)?

I think some new stuff is coming for this in 1.5, but for 1.4 it's still
fairly easy to do.  See
http://stripes.sourceforge.net/docs/current/javadoc/net/sourceforge/stripes/exception/DelegatingExceptionHandler.html

You'll need this in your web.xml:

<init-param>
     <description>Stripes exception handler</description>
     <param-name>ExceptionHandler.Class</param-name>
 
<param-value>net.sourceforge.stripes.exception.DelegatingExceptionHandler</param-value>
</init-param>
<init-param>
     <description>Stripes exception resolver filter</description>
     <param-name>DelegatingExceptionHandler.UrlFilters</param-name>
     <param-value>WEB-INF/classes</param-value>
</init-param>

The I have a class like this:

public class UploadExceptionHandler implements AutoExceptionHandler {

     /**
      * Handle a file upload exception.
      * @param e the exception to handle.
      * @param request the upload request.
      * @param response the upload response.
      * @return a redirect to the error page.
      */
     public Resolution handle(FileUploadLimitExceededException e,
       HttpServletRequest request, HttpServletResponse response) {
         RedirectResolution r =
           new RedirectResolution("/error/upload.jsp");
         r.addParameter("posted", e.getPosted() / 1048576.0);
         r.addParameter("maximum", e.getMaximum() / 1048576.0);
         return r;
     }
}

And a JSP like this:

         <h2>File Upload Error</h2>
         <p class="error">
         You attempted to upload a file that was
         <fmt:formatNumber value="${param.posted}"
             maxFractionDigits="1"/>Mb
         in size, the maximum allowed file size is
         <fmt:formatNumber value="${param.maximum}"
             maxFractionDigits="1"/>Mb.
         Please only upload valid files.
         </p>

--
Alan Burlison
--

-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php
_______________________________________________
Stripes-users mailing list
Stripes-users@...
https://lists.sourceforge.net/lists/listinfo/stripes-users

Re: How to handle exception on File Upload in stripes.

by Tissen Sebastian :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Thank you alan. It was a realy a great help..


 
On Sun, Jun 29, 2008 at 10:25 PM, Alan Burlison <Alan.Burlison@...> wrote:
Tissen wrote:

> Could anybody suggest a way to handle this exception (not using
> commong Error page)?

I think some new stuff is coming for this in 1.5, but for 1.4 it's still
fairly easy to do.  See
http://stripes.sourceforge.net/docs/current/javadoc/net/sourceforge/stripes/exception/DelegatingExceptionHandler.html

You'll need this in your web.xml:

<init-param>
    <description>Stripes exception handler</description>
    <param-name>ExceptionHandler.Class</param-name>

<param-value>net.sourceforge.stripes.exception.DelegatingExceptionHandler</param-value>
</init-param>
<init-param>
    <description>Stripes exception resolver filter</description>
    <param-name>DelegatingExceptionHandler.UrlFilters</param-name>
    <param-value>WEB-INF/classes</param-value>
</init-param>

The I have a class like this:

public class UploadExceptionHandler implements AutoExceptionHandler {

    /**
     * Handle a file upload exception.
     * @param e the exception to handle.
     * @param request the upload request.
     * @param response the upload response.
     * @return a redirect to the error page.
     */
    public Resolution handle(FileUploadLimitExceededException e,
      HttpServletRequest request, HttpServletResponse response) {
        RedirectResolution r =
          new RedirectResolution("/error/upload.jsp");
        r.addParameter("posted", e.getPosted() / 1048576.0);
        r.addParameter("maximum", e.getMaximum() / 1048576.0);
        return r;
    }
}

And a JSP like this:

        <h2>File Upload Error</h2>
        <p class="error">
        You attempted to upload a file that was
        <fmt:formatNumber value="${param.posted}"
            maxFractionDigits="1"/>Mb
        in size, the maximum allowed file size is
        <fmt:formatNumber value="${param.maximum}"
            maxFractionDigits="1"/>Mb.
        Please only upload valid files.
        </p>

--
Alan Burlison
--

-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php
_______________________________________________
Stripes-users mailing list
Stripes-users@...
https://lists.sourceforge.net/lists/listinfo/stripes-users



--
Cheers,
Tissen Sebastian
-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php
_______________________________________________
Stripes-users mailing list
Stripes-users@...
https://lists.sourceforge.net/lists/listinfo/stripes-users
LightInTheBox - Buy quality products at wholesale price