Note that there are some explanatory texts on larger screens.

plurals
  1. POcatch exception in JSP
    primarykey
    data
    text
    <p>I want to know how to handle this situation and what do you recommend for this. </p> <p>I am having a null pointer exception in my JSP. </p> <pre><code>String csvDataIn = new String ((String)request.getAttribute("csvString")); </code></pre> <p>This is because, I have created a Controller in spring in order to handle the querying to the DB and get a csvString. Everything is working fine, until I made a query that is failing. </p> <p>So, in the controller:</p> <pre><code> ... JsonNode json = dataRepository.getDataAsJson(dataNode); csvString = getCSVfromJsonNode(json); model.addAttribute("csvString", csvString); } catch (Exception e) { Logger.log("CSV controller failed", _moduleClass, e); } return "exportCSV"; } </code></pre> <p>So the variable json is never been fill it, because the function getDataAsJson() is failing. So this is throwing an exception. And then I am returning back to the exportCSV.jsp, but I am not returning the attribute csvString in the model.</p> <p>So, back in the jsp, is throwing the nullpointer exception.</p> <p>So my questions are: a- How you will catch this exceptions in the JSP? b- Do you think a better solution, than catch the exception in the JSP? I mean what could be the best practice for this.</p> <p>Thanks in advance.</p> <p>Thanks for the responses. They are really good help: I made the following modifications in order to handle the problem. </p> <pre><code> ... JsonNode json = dataRepository.getDataAsJson(dataNode); model.addAttribute("csvString", csvString); } catch (Exception e) { Logger.log("CSV controller failed", _moduleClass, e); } return "exportCSV"; csvString = getCSVfromJsonNode(json); } </code></pre> <p>This solve the problem for sending a Null String, since the csvString is bean created before, empty.</p> <p>The exception that I am getting in here is javax.xml.ws.webserviceexception could not send message (do you know a better way to handle this at the controller?)</p> <p>I also did this in the jsp side, just in case:</p> <pre><code>String csvDataIn = (String)request.getAttribute("csvString"); //This should never happen, but we check anyway. if (csvDataIn != null){ ... } </code></pre> <p>So the only doubt that I may remain is: do you know a better way to handle javax.xml.ws.webserviceexception at the controller?</p> <p>THANKS AGAIN</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload