How to pass exception message to an HTML page from a JSP?

1

I have a college exercise in which I have to create a .jsp page that receives a "id" parameter and runs a query to delete the record inside the class products with this id and in case of any exception I send the user to page error.html passing as parameter the text of the error. The code I've made so far is this:

<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1" import="web.acesso.bd.*,web.acesso.bd.dao.*"%>
<html>  
<head><title>Insert title here</title></head>  
<body>   
<% 
int myId=request.getParameter("id")
try{
    bd.execComando ("DELETE FROM Filme id="+myId+");
} 
catch(Exception e)
{
   response.sendRedirect("erro.html");
}%>  
</body>  
</html>

So far I think that's right, but I do not know how to pass as parameter the exception message that is in the variable "and". Could someone help?

    
asked by anonymous 01.12.2014 / 20:58

1 answer

4

Maybe something like this will solve:

<% 
   int myId=request.getParameter( "id" );

   try{
      bd.execComando ( "DELETE FROM Filme WHERE id=" + myId );
   } 
   catch( Exception e )
   {
      response.sendRedirect( "erro.html?excecao=" + URLEncoder.encode( e, "ISO-8859-1" ) );
   }
%>

The URLencoder will convert spaces and special characters into a message that can be transmitted exactly by URL, just by setting the conversion to what you need. I put ISO-8859-1 for being the same one you used in the first line of the original code.

This is clear, assuming that the intent is for the error page to process the excecao parameter to display to the end user.

    
01.12.2014 / 21:03