AJAX JSP displaying output data in a table - html

trying to display data from server in the page in a table. but unfortunately it is not working. I can display it using out.println. Code samples are attached. Thank you very much.
ajax1 handles the ajax part and ajax2 is the file for java code.
...
Ajax1.jsp
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script src="https://code.jquery.com/jquery-1.10.2.js"></script>
<script>
$(document).ready(function(){
$("#users").change(function(){
var value = $(this).val();
$.get("ajax2.jsp",{q:value},function(data){
$("#javaquery").html(data);
});
});
});
</script>
</head>
<body>
<select id = "users">
<option value="">Select Account ID</option>
<option value="calicut">calicut</option>
<option value="kochi">kochi</option>
<option value="Admin">Admin</option>
</select>
<br />
<div id="javaquery"><b>Name will be displayed here</b></div>
</body>
</html>
Ajax2.jsp
<%#page import="java.text.SimpleDateFormat"%>
<%#page contentType="text/html" pageEncoding="UTF-8"%>
<%#page import="java.util.*,java.sql.*,java.io.*" %>
<%#page import="javax.servlet.*" %>
<%#page import="javax.servlet.http.*" %>
<%# page import="java.sql.*" %>
<%# page import="java.util.*" %>
<%# page import="java.io.*" %>
<%# page import="javax.sql.*" %>
<%# page import="javax.naming.*,javax.swing.*,java.sql.Date.*,java.text.SimpleDateFormat.*,java.util.Date.*" %>
<html> <head> <meta http-equiv="Content-Type"
content="text/html; charset=UTF-8"> <title></title> </head>
<body>
<%
InitialContext ctx;
DataSource ds;
Connection conn;
ResultSet rs;
Statement stmt;
String name = "";
String ename="";
try {
ctx=new InitialContext();
ds=(DataSource) ctx.lookup("java:app/jdbc/SalesDB");
conn=ds.getConnection();
String q = request.getParameter("q");
stmt = conn.createStatement(); //Create Statement to interact
rs = stmt.executeQuery("select * from employees where Username='"+q+"'");
while (rs.next()) {
name = rs.getString("Role_")+rs.getString("username");
ename=rs.getString("username");
}
rs.close();
stmt.close();
conn.close();
} catch (Exception e) {
e.printStackTrace();
}
%>
Name:<%out.print(name);%>
eName:<%out.print(ename);%>
</body> </html>
.............................................
.................................................

<script>
$(document).ready(function(){
$("#users").change(function(){
var value = $(this).val();
$.get("AjaxServlet",{q:value},function(data){
$("#javaquery").html(data);
});
});
});
</script>
Remove java code from 2nd jsp and add it to a servlet called "AjaxServlet" with url mapping "/AjaxServlet"
AjaxServlet:
#Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String q = request.getParameter("q"); //q value
InitialContext ctx;
DataSource ds;
Connection conn;
ResultSet rs;
Statement stmt;
String name = "blank name";
String ename="";
try {
ctx=new InitialContext();
ds=(DataSource) ctx.lookup("java:app/jdbc/SalesDB");
conn=ds.getConnection();
String q = request.getParameter("q");
stmt = conn.createStatement(); //Create Statement to interact
rs = stmt.executeQuery("select * from employees where Username='"+q+"'");
while (rs.next()) {
name = rs.getString("Role_")+rs.getString("username");
ename=rs.getString("username");
}
rs.close();
stmt.close();
conn.close();
} catch (Exception e) {
e.printStackTrace();
}
response.setContentType("text/plain"); // Set content type of the response so that jQuery knows what it can expect.
response.setCharacterEncoding("UTF-8"); // You want world domination, huh?
response.getWriter().write(name); // Write response body.
}
More info on how to do ajax with servlets here:
How to use Servlets and Ajax?

Related

SQL update query is not working in Java program

I am trying to update record in MySQL table. But when I execute it, it is not reflecting changes. No error or exceptions occurred. I tried with con.commit() and con.setAutoCommit(false) but no changes reflected. Only Home button is displayed on screen and even alerts in my program not displayed.
This is editnew.jsp
<tr>
<td></td>
<td>
<input type="hidden" value="update" name="update"/>
<input type="submit" value="Update" class="btn btn-primary"/>
</td>
</tr>
This is my editprocess.jsp code
<%#page import="java.io.File"%>
<%#page import="java.sql.*"%>
<%#page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css">
<title>editprocess jsp Page</title>
</head>
<body>
<%
String z_id = request.getParameter("zid");
String first_Name = request.getParameter("firstname");
String last_Name = request.getParameter("lastname");
String mail_i_d = request.getParameter("mailid");
String d_iv = request.getParameter("division");
String de_pt = request.getParameter("department");
...
String iss_uer = request.getParameter("issuer");
String sta_tus = request.getParameter("status");
String file_Name = "";
String folder_Name = "allfiles";
String pa_th = folder_Name + File.separator + file_Name;
Timestamp add_ed_date = new Timestamp(System.currentTimeMillis());
if(request.getParameter("update") != null){
Connection con = null;
PreparedStatement ps = null;
try{
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection("jdbc:mysql://localhost:3306/dmsqms","root","");
String sql = "update dmsfiles set firstname=?,lastname=?,mailid=?,division=?,department=?,costcentercode=?,document_number=?,document_name=?,document_type=?,document_category=?,document_classification=?,authorised_by=?,fromdate=?,todate=?,document_level=?,document_general=?,serial_number=?,revision_number=?,issuer=?,status=?,filename=?,path=?,added_date=? where document_name='"+doc_Name+"'";
ps = con.prepareStatement(sql);
// ps.setString(1,z_id);
ps.setString(1,first_Name);
ps.setString(2,last_Name);
ps.setString(3,mail_i_d);
ps.setString(4,d_iv);
ps.setString(5,de_pt);
ps.setString(6,cost_centercode);
ps.setString(7,doc_num);
ps.setString(8,doc_Name);
ps.setString(9,doc_Type);
ps.setString(10,doc_Category);
ps.setString(11,doc_classification);
ps.setString(12,authorised_by);
ps.setString(13,from_date);
ps.setString(14,to_date);
ps.setString(15,document_level);
ps.setString(16,document_general);
ps.setString(17,serial_number);
ps.setString(18,revision_number);
ps.setString(19,iss_uer);
ps.setString(20,sta_tus);
ps.setString(21,file_Name);
ps.setString(22,pa_th);
ps.setTimestamp(23, add_ed_date);
int i = ps.executeUpdate(sql);
con.commit();
if(i > 0)
{
out.println("alert('Record Updated Successfully');");
}
else
{
out.println("alert('There is a problem in updating Record.');");
}
}
catch(SQLException sql)
{
sql.printStackTrace();
}
}
%>
Home
</body>
</html>

com.mysql.jdbc.Driver cannot be found by de Server

I have a web application that has been working for ages now.. suddenly I get this message when I am trying to login:
javax.servlet.ServletException: java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
As I said before it has been working for over 3 years now… but the people who does the hosting for me have not been able to do anything… I have my driver on the WEB-INF folder and everything… can the folder’s permissions cause this problem? I have them set as 0744…any idea?
This is the screen shot of the WEB-INF folder:
I managed to login to the web application but the login jsp file is not working because the connection is not happening… here is the code:
<%# page contentType="text/html; charset=utf-8" language="java" import="java.sql.*" errorPage="" %>
<%# page language="java" session="true" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Accesando a Vecinet</title>
</head>
<body>
<%
Connection conn = null;
Class.forName("com.mysql.jdbc.Driver").newInstance();
conn = DriverManager.getConnection("jdbc:mysql://localhost/etoolsco_VecinetSM?user=etoolsco&password=xxxx");
ResultSet rsdoLogin = null;
PreparedStatement psdoLogin=null;
String uname=request.getParameter("j_username");
String upass=request.getParameter("j_password");
String message="User login successfully ";
%>
<% try
{
String sqlOption="SELECT * FROM logins where"
+" usuario=? and clave=?";
psdoLogin=conn.prepareStatement(sqlOption);
psdoLogin.setString(1,uname);
psdoLogin.setString(2,upass);
rsdoLogin=psdoLogin.executeQuery();
if(rsdoLogin.next())
{
session.setAttribute("usuario",rsdoLogin.getString("usuario"));
session.setAttribute("clave",rsdoLogin.getString("clave"));
session.setAttribute("nombre",rsdoLogin.getString("nombre"));
session.setAttribute("apellido",rsdoLogin.getString("apellido"));
session.setAttribute("role",rsdoLogin.getString("role"));
session.setMaxInactiveInterval(7200);
response.sendRedirect("Vecinetspace.jsp?error="+message);
}
else
{
response.sendRedirect("error.jsp?error=");
}
}
catch(Exception e)
{
e.printStackTrace();
}
try{
if(psdoLogin!=null){
psdoLogin.close();
}
if(rsdoLogin!=null){
rsdoLogin.close();
}
if(conn!=null){
conn.close();
}
}
catch(Exception e)
{
e.printStackTrace();
}
%>
</body>
</html>
This is the same login.jsp code for the application that is working:
<%#page contentType="text/html"%>
<%#page pageEncoding="UTF-8"%>
<%# page language="java" import="java.sql.*" errorPage="" %>
<%# page language="java" session="true" %>
<html>
<head><title>Login to CRD</title>
</head>
<body>
<%
Connection conn = null;
Class.forName("com.mysql.jdbc.Driver").newInstance();
conn = DriverManager.getConnection("jdbc:mysql://localhost/etoolsco_labsmb?user=etoolsco&password=xxx");
ResultSet rsdoLogin = null;
PreparedStatement psdoLogin=null;
String uname=request.getParameter("j_username");
String upass=request.getParameter("j_password");
String message="User login successfully ";
%>
<% try
{
String sqlOption="SELECT * FROM logins where"
+" usuario=? and clave=?";
psdoLogin=conn.prepareStatement(sqlOption);
psdoLogin.setString(1,uname);
psdoLogin.setString(2,upass);
rsdoLogin=psdoLogin.executeQuery();
if(rsdoLogin.next())
{
session.setAttribute("usuario",rsdoLogin.getString("usuario"));
session.setAttribute("clave",rsdoLogin.getString("clave"));
session.setAttribute("nombre",rsdoLogin.getString("nombre"));
session.setAttribute("apellido",rsdoLogin.getString("apellido"));
session.setAttribute("role",rsdoLogin.getString("role"));
session.setMaxInactiveInterval(600);
response.sendRedirect("BMRspace.jsp?error="+message);
}
else
{
response.sendRedirect("error.jsp?error=");
}
}
catch(Exception e)
{
e.printStackTrace();
}
try{
if(psdoLogin!=null){
psdoLogin.close();
}
if(rsdoLogin!=null){
rsdoLogin.close();
}
if(conn!=null){
conn.close();
}
}
catch(Exception e)
{
e.printStackTrace();
}
%>
</body>
</html>

how to extract data from excel (apache poi) to put it in mysql table using jsp?

I want to extract data from excel sheet to insert it into a mysql table using jsp, so far i've done this and its printing data into the outpout(using apache poi),what should i add to this code ?
Output :
Name Age Adress
Mark 35 New york,AA
Elise 22 India,bb
Charlotte 45 France,cc
Readexcel.jsp :
<%#page import="java.sql.Statement"%>
<%#page import="java.util.ArrayList"%>
<%#page import="java.sql.PreparedStatement"%>
<%#page import="java.sql.Connection"%>
<%#page import="java.util.Date"%>
<%#page import="org.apache.poi.ss.usermodel.Cell"%>
<%#page import="org.apache.poi.ss.usermodel.Row"%>
<%#page import="org.apache.poi.xssf.usermodel.XSSFSheet"%>
<%#page import="org.apache.poi.xssf.usermodel.XSSFWorkbook"%>
<%#page import="java.io.File"%>
<%#page import="org.apache.commons.io.FilenameUtils"%>
<%#page import="org.apache.commons.fileupload.FileItem"%>
<%#page import="java.util.Iterator"%>
<%#page import="java.util.List"%>
<%#page import="org.apache.commons.fileupload.servlet.ServletFileUpload"%>
<%#page import="org.apache.commons.fileupload.disk.DiskFileItemFactory"%>
<%#page import="org.apache.commons.fileupload.FileItemFactory"%>
<%#page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>PRINT DATA FROM EXCEL FILE</title>
</head>
<body>
<%
try{
boolean ismultipart=ServletFileUpload.isMultipartContent(request);
if(!ismultipart){
}else{
FileItemFactory factory = new DiskFileItemFactory();
ServletFileUpload upload = new ServletFileUpload(factory);
List items = null;
try{
items = upload.parseRequest(request);
}catch(Exception e){
}
Iterator itr = items.iterator();
while(itr.hasNext()){
FileItem item = (FileItem)itr.next();
if(item.isFormField()){
}else{
String itemname = item.getName();
if((itemname==null || itemname.equals(""))){
continue;
}
String filename = FilenameUtils.getName(itemname);
File f = checkExist(filename);
item.write(f);
try{
XSSFWorkbook workbook = new XSSFWorkbook(item.getInputStream());
XSSFSheet sheet = workbook.getSheetAt(0);
Iterator<Row> rowIterator = sheet.iterator();
while (rowIterator.hasNext()){
Row row = rowIterator.next();
Iterator<Cell> cellIterator = row.cellIterator();
while (cellIterator.hasNext())
{
Cell cell = cellIterator.next();
switch (cell.getCellType()){
case Cell.CELL_TYPE_NUMERIC:
out.print(cell.getNumericCellValue() + "t");
break;
case Cell.CELL_TYPE_STRING:
out.print(cell.getStringCellValue() + "t");
break;}
}
out.println("");
}
}catch (Exception e){
e.printStackTrace();
}
}
}
}
}catch(Exception e){
}
finally {
out.close();
}
%>
<%!
private File checkExist(String fileName){
String saveFile = "D:/upload/";
File f = new File(saveFile+"/"+fileName);
if(f.exists()){
StringBuffer sb = new StringBuffer(fileName);
sb.insert(sb.lastIndexOf("."),"-"+new Date().getTime());
f = new File(saveFile+"/"+sb.toString());
}
return f;
}
%>
</body>
</html>
I've created a table in my database named EXCELDATA with the header of the excel sheet :
ExcelData (Name varchar(50),age int,adress varchar(50));
what should i add to this code to get the data from the excel sheet to the mysql table ??
This is my excelimport.jsp file
try{
String name,age,address=null;
Class.forName("com.mysql.jdbc.Driver");
Connection con = (Connection) DriverManager.getConnection("jdbc:mysql://localhost:3306/dbname","username","password");
con.setAutoCommit(false);
PreparedStatement pstm = null ;
FileInputStream input = new FileInputStream("C://yourexcelfile.xls");
POIFSFileSystem fs = new POIFSFileSystem( input ); //creating a new poi reference to the given excel file
HSSFWorkbook wb = new HSSFWorkbook(fs);
HSSFSheet sheet = wb.getSheetAt(0);
Row row;
Statement st=con.createStatement();
for(int i=1; i<=sheet.getLastRowNum(); i++){ //points to the starting of excel i.e excel first row
row = (Row) sheet.getRow(i); //sheet number
if( row.getCell(0)==null) { name = "0";} //suppose excel cell is empty then its set to 0 the variable
else name = row.getCell(0).toString(); //else copies cell data to name variable
if( row.getCell(1)==null) { age = "0"; }
else age= row.getCell(1).toString();
if( row.getCell(2)==null) { address = "0"; }
else address = row.getCell(2).toString();
String sq="INSERT INTO ExcelData(name,age,address) VALUES('"+name+"','"+age+"','"+address+"')";
pstm = (PreparedStatement) con.prepareStatement(sq);//here we are using prepared statement because we are calling this statement for each row
pstm.execute();
System.out.println("Import rows "+i);
}
con.commit();
pstm.close();
con.close();
input.close();
System.out.println("Success import excel to mysql table");
}catch(ClassNotFoundException e){
out.println(e);
}catch(SQLException ex){
out.println(ex);
}catch(IOException ioe){
out.println(ioe);
}
%>

Display image in asp div

My problem is that, after i was able to display my medium blob in mysql database in my jsp, i cannot position the image with my css.
What i want is to position it inside a div that has a fixed width and height.
<%#page import="java.io.OutputStream"%>
<%#page contentType="text/html" pageEncoding="UTF-8" import="java.sql.*"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<%
Statement stmnt = null;
ResultSet rs = null;
OutputStream o = null;
String driver = "com.mysql.jdbc.Driver";
String url = "jdbc:mysql://localhost/uShare";
String username = "root";
String password = "";
PreparedStatement ps;
Blob image = null;
byte[] imgData = null;
try {
Class.forName(driver).newInstance();
Connection con = DriverManager.getConnection(url, username, password);
stmnt = con.createStatement();
rs = stmnt.executeQuery("select foto from utilizadores where idUtilizador = 13");
if (rs.next()) {
image = rs.getBlob("foto");
imgData = image.getBytes(1, (int) image.length());
out.println("encontrou imagem");
}
//mostra
response.setContentType("image/gif");
o = response.getOutputStream();
o.write(imgData);
%>
<div style="float: right; width: 20%; height: 20%;">
<%
o.flush();
%>
</div>
<%
o.close();
stmnt.close();
con.close();
} catch (SQLException ex) {
ex.printStackTrace();
}
%>
</body>
</html>
Thank you to all.
Sorry for the late answer but the site doesn't let me reply within 8 hours.T hanks to everyone. I found a temporary solution, and because this is for academic purposes only it´s ok.
The solution is. When i want to display a image in a ing tag, i always have to give the tag the url.
There are two possibilities:
you cam pass the image through servlet;
Or like the one i did, i displayed the image in a Jsp page then i grab it on the other jsp with the first jsp url.
Jsp for display the image:
<%#page import="java.io.OutputStream"%>
<%#page contentType="text/html" pageEncoding="UTF-8" import="java.sql.*"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
<link href="css/master.css" rel="stylesheet" type="text/css">
</head>
<body>
<%
Statement stmnt = null;
ResultSet rs = null;
OutputStream o = null;
String driver = "com.mysql.jdbc.Driver";
String url = "jdbc:mysql://localhost/uShare";
String username = "root";
String password = "";
PreparedStatement ps;
Blob image = null;
byte[] imgData = null;
try {
Class.forName(driver).newInstance();
Connection con = DriverManager.getConnection(url, username, password);
stmnt = con.createStatement();
rs = stmnt.executeQuery("select foto from utilizadores where idUtilizador = 13");
if (rs.next()) {
image = rs.getBlob("foto");
imgData = image.getBytes(1, (int) image.length());
out.println("encontrou imagem");
}
//mostra
response.setContentType("image/jpeg");
o = response.getOutputStream();
o.write(imgData);
o.flush();
response.flushBuffer();
stmnt.close();
con.close();
} catch (SQLException ex) {
ex.printStackTrace();
}
%>
</body>
</html>
And then the end user jsp
<%#page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<img src="testeImagem.jsp" alt="foto" style="width: 200px; height: 200px">
</body>
</html>
Of course this is just an example.
Thanks to all, and sorry for my bad english.
set image width as 100% so that it will get fit inside a fixed length of div

how to display multiple images and data from mysql in jsp

I am using jsp with mysql in these code. i got only one images at a time but all data retrieved... Can u tell me how to display multiple images in this code?
my data: imagename varchar(),description varchar(),imageid varchar(),category varchar image blob().
index.jsp:
<%#page import="java.io.InputStream"%>
<%#page contentType="text/html" pageEncoding="UTF-8"%>
<%#page import="java.io.OutputStream"%>``
<%# page import="java.sql.*" %>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<%
Class.forName("com.mysql.jdbc.Driver");
Connection con=DriverManager.
getConnection("jdbc:mysql://localhost:3306/rich","root","");
Statement stmt = con.createStatement();
ResultSet rs=stmt.executeQuery("select *from publishers");
while(rs.next())
{
String imgLen=rs.getString(5);
int len = imgLen.length();
byte [] rb = new byte[len];
InputStream readImg = rs.getBinaryStream(5);
int index=readImg.read(rb, 0, len);
System.out.println("index"+index);
stmt.close();
response.reset();
response.setContentType("image/jpg");
response.getOutputStream().write(rb,0,len);
response.getOutputStream().flush();
}
%>
</body>
</html>
**basic.jsp:**
<%#page contentType="text/html" pageEncoding="UTF-8"%>
<%#page import="java.io.OutputStream"%>
<%# page import="java.sql.*" %>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
< form action="index.jsp" method="post">
<%
Class.forName("com.mysql.jdbc.Driver");
Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/rich","root","");
Statement stmt = con.createStatement();
ResultSet rs=stmt.executeQuery("select *from publishers");
while(rs.next())
{
%>
<table border="1">
<tr> <td>
<img src="index.jsp?" /> </td> </tr>
<tr>
<td> <%=rs.getString(1)%> </td>
<td> <%=rs.getString(2)%> </td>
<td> <%=rs.getString(3)%> </td>
<td> <%=rs.getString(4)%> </td>
</tr>
</table>
<%
}
%>
</form>
</body>
</html>
Actually it is not difficult . We will use two jsps files to show images first this page for getting image.
<%# Page import="java.sql.*" %>
<%# Page import="java.io.*" %>
<html>
<%
byte[] imgData = null;
try
{
Class.forName("com.mysql.jdbc.Driver");
Connection con =
DriverManager.getConnection("jdbc:mysql://localhost/try","root","root");
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("select photo from employee where employee_id=" + request.getParameter("empId"));
while (rs.next())
{
Blob image = rs.getBlob(1);
imgData = image.getBytes(1,(int)image.length());
}
response.setContentType("image/png");
OutputStream o = response.getOutputStream();
o.flush();
o.close();
rs.close();
stmt.close();
con.close();
}
catch (Exception e)
{
out.println("Unable To Display image");
out.println("Image Display Error=" + e.getMessage());
return;
}
%>
</html>
and here i getting all ids to get all images
<%# page import="java.sql.*"%>
<%# page import="java.io.*"%>
<html>
<%
try
{
String EmpFirstName;
String EmpSurname;
String EmpId;
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost/try","root","root");
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("select employee_id,first_name,surname from employee");
while (rs.next())
{
EmpFirstName = rs.getString("first_name");
EmpSurname = rs.getString("surname");
EmpId = rs.getString("EmpId");
<DIV><%=EmpFirstName5> <%=Surname%> </DIV>
<img src="http://localhost/GetImage.jsp?empId=<%=EmpId%>" />
}
rs.close();
stmt.close();
con.close();
}
catch (Exception e)
{
out.println(e.Message);
return;
}
%>
</html>
the code and its explanation taken from
http://stackoverflow.com/users/535152/tom%c3%a1s
thank you very much