Good discussion. I also had this question. This is my POV and expecting
expert opinions.

Usually JSPs are in the presentation layer and resides in the web
container. You don't have to worry about logging the error unless it is
induced specifically at the JSP level because in the down area Servlets and
EJBs has already logged the error.

Having said that; JSP should present the error to the higher level in a
standard way(confirmed to agreed protocol JSON, XML or HTML) since you are
invoking it through AJAX.

Usually it is not encouraged to use `e.printStackTrace()` on the production
stage as it drags you into the security issues. If you really need it; use;

<% // JSP scriptlet
try{
   // An Exception is thrown
}catch(Exception e){
   e.printStacktrace(new java.io.PrintWriter(out));
}
%>

Rasika Perera

On Sat, Feb 7, 2015 at 7:55 PM, Hemika Kodikara <[email protected]> wrote:

> Can I get some advice on this ?
>
> Is it necessary to put a e.printStackTrace() if an error is caught at JSP
> level ?
>
> Hemika Kodikara
> Software Engineer
> WSO2 Inc.
> lean . enterprise . middleware
> http://wso2.com
>
> Mobile : +94777688882
>
> On Mon, Jan 26, 2015 at 11:38 AM, Hemika Kodikara <[email protected]> wrote:
>
>> Hi All,
>>
>> What is the correct way to handle an exception when it comes to JSP pages
>> ?
>>
>> Currently I have the following AJAX call on a JS file. This is called
>> from another JSP file.
>>
>> function updatePermissions() {
>>     var callback =
>>     {
>>         success:function(o) {
>>             if (o.responseText !== undefined) {
>>                 if (o.responseText.indexOf("Error") > -1) {
>>                     CARBON.showErrorDialog("" + o.responseText,
>> function() {
>>                         location.href = "../queues/queue_details.jsp"
>>                     });
>>                 } else {
>>                     CARBON.showInfoDialog("" + o.responseText, function()
>> {
>>                         location.href = "../queues/queue_details.jsp"
>>                     });
>>                 }
>>
>>             }
>>         },
>>         failure:function(o) {
>>             if (o.responseText !== undefined) {
>>                 alert("Error " + o.status + "\n Following is the message
>> from the server.\n" + o.responseText);
>>             }
>>         }
>>     };
>>     var request = YAHOO.util.Connect.asyncRequest('POST',
>> "update_queue_role_permissions_ajaxprocessor.jsp", callback);
>> }
>>
>>
>> The call is going to the the following file
>> (update_queue_role_permissions_ajaxprocessor.jsp)
>> update_queue_role_permissions_ajaxprocessor.jsp
>> =======================================
>> <%
>>     // some code
>>     QueueRolePermission[] queueRolePermissions = new
>> QueueRolePermission[queueRolePermissionArrayList.size()];
>>     try {
>>         // some code
>>         stub.updatePermission(queue,
>> queueRolePermissionArrayList.toArray(queueRolePermissions));
>>         message = "Queue added successfully";
>>     } catch (AndesAdminServiceBrokerManagerAdminException e) {
>>         // what to do here ?
>>         message = "Error in adding/updating permissions : " +
>> e.getMessage();
>>     }
>> %><%=message%>
>>
>>
>> Concerns :
>> 1. When an exception is caught, should the exception be logged at the JSP
>> catch block or logged at where it is occurring at the higher level of code
>> where the exception was thrown ?
>>
>> 2. If the exception is being logged at the JSP level, should it use log4j
>> or an e.printStackTrace() ? e.printStackTrace usage at [1].
>>
>> [1] - https://docs.wso2.com/display/Governance460/Transition+UI+Sample
>>
>> Regards,
>> Hemika
>>
>> Hemika Kodikara
>> Software Engineer
>> WSO2 Inc.
>> lean . enterprise . middleware
>> http://wso2.com
>>
>> Mobile : +94777688882
>>
>
>
> _______________________________________________
> Dev mailing list
> [email protected]
> http://wso2.org/cgi-bin/mailman/listinfo/dev
>
>


-- 
With Regards,

*Rasika Perera*
Software Engineer
M: +94 71 680 9060 E: [email protected]
LinkedIn: http://lk.linkedin.com/in/rasika90

WSO2 Inc. www.wso2.com
lean.enterprise.middleware
_______________________________________________
Dev mailing list
[email protected]
http://wso2.org/cgi-bin/mailman/listinfo/dev

Reply via email to