Skip to main content
New Participant
December 6, 2016

Best practise to log in JSP file

  • December 6, 2016
  • 4 replies
  • 8064 views

Hi,

 

I would appreciate it if anyone could please point out to me any development article that would help me follow best practices in logging errors on a try {} catch () {} in JSP.

Regards

Clive Stewart

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.

4 replies

Peter_Puzanovs
New Participant
December 6, 2016

Hi Clive,

It seems like Adobe(view from outside) are moving away from jsp code with lot's of inline Java code.

Have you looked at more modern practices such as HTL's and Sling Models(look like more modern practices)?

Regards,

Peter

New Participant
December 7, 2016

Hi Peter,

 

Unfortunately I am working on code written by other developers. They do not want to move to HTL. So when I look through their code all try {} catch() {} code suppress all errors. E.g
try {
Some Java code to read a resource
} catch (Exception e) {}

 

So I must make best of it as I cannot follow the best practice, which to me is use HTL (avoid JSP) and OSGI for business logic (i.e. do not have the java code for this in a jsp) , and where JSP is used keep the java simple. If its complex place it in OSGI. If it acceses JCr and othe Db resources, place it in OSGI.

 

But that is not up to me, so hence I am trying to think of what is the best way in AEM with JSP.
The simplest answer is to use the available implicit object, log as follows
=>  log.error("my error",e).

diptinarang
New Participant
December 6, 2016

Hi Cleve

I generally use Approach 1 mentioned here: http://www.codejava.net/java-ee/jsp/how-to-handle-exceptions-in-jsp

~Dipti

New Participant
December 6, 2016

Thank you for the helpful information