Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How to access the exit status of a java code in JSP page?  RSS feed

 
Mg Ray
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a JavaBean where the method createLoanRecord() is definded. (It gets the memberID and bookID from jsp and create a book loan record)

public void createLoanRecord()
{
try{
Date d = new Date();
book = book_server.readBook(bookID);
loan.setBookId(book);
loan.setLoandate(d);
member = member_server.readMember(memberID);
loan.setMemberId(member);
loan_server.createLoan(loan);

}catch (Exception e)
{

}

}

How can I access the exit status of the same through my JSP? I am calling this method in a JSP like the following

<c:when test="${not empty param.bookSelect}">

<% loanInstance.createLoanRecord(); %>

</c:when>


This setup runs fine but does not provide any relevant message to the user of the system. I want to show the output message as well based on the success or failure of the method.

Any help would be much appreciated. Also please let me know if I need to paste the whole content of the program files.

Many Thanks in Advance.

 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65826
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You should not be mixing JSTL and scriptlets! That's just a big old mess waiting to happen. Why must this code be called from a JSP?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65826
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In any case, the way that show stuff to users on an HTML page is to generated the HTML that shows what you want.
 
Mg Ray
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The reason being the user of the system will click a select button corresponding to a book entry to make a book loan from a library system. If the book is already taken by another user, the createLoanRecord() method will through an exception as the database won't allow it. I want to capture this case so that the user will see a message like "this book has already been taken" or for that matter,if the book can be taken as loan, the message "This book has been added to the loan" should appear. As per the present design, no such message comes for either cases.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65826
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That is the sort of logic that should be handled in the model, not the view.

Regardless, when the info that something is wrong reaches the JSP, it must generate the HTML that displays any messages to the user.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!