Good day java People
I am attempting to build a jsp page that connects to a MS SQL 2008 database and retrieves information and displays it on the web page however when i run my jsp script it seems only the html part gets executed and reflected on the output(the web page) the java code seems not to be executing, im thinking mayb glassfish does not support JSP or there is something wrong with my code. Please see below what i have done to set up this project
1)Downloaded and set up appopriate driver for MS SQL server connection in Netbeans (used 'net.sourceforge.jtds.jdbc.Driver')
2)Setup Glassfish Server 4 as my web server in netbeans
3)connection between application and database established successfully.
Please see code below and attached please find the what the output looks like after running the below code
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<%@page import="java.sql.*;"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Mr price Summary</title>
</head>
<body bgcolor="teal">
<center>
<h1>This is the Mr Price Summary</h1>
<% String user = "sa"; String pass = "p@ssword123"; String data = "jdbc:jtds:sqlserver://localhost:1433;databaseName=SolarWindsOrion"; System.setProperty("jdbc.drivers","net.sourceforge.jtds.jdbc.Driver"); try { Class.forName("net.sourceforge.jtds.jdbc.Driver"); Connection conn = DriverManager.getConnection( data,user,pass); Statement state = conn.createStatement(); ResultSet resultset = state.executeQuery("SELECT a.Caption, a.IP_Address, b.Model, b.ServiceTag, a.PONumber FROM Nodes a JOIN APM_HardwareInfo b ON a.NodeID = b.NodeID WHERE Department = 'mrprice'"); while(resultset.next()){ %>
<table border="1" >
<tr>
<th>Device Name</th>
<th>IP Address</th>
<th>Model</th>
<th>Serial Number</th>
<th>Region</th>
</tr>
<tr>
<td><%=resultset.getString("a.Caption")%></td>
<td><%=resultset.getString("a.IP_Address")%></td>
<td><%=resultset.getString("b.Model")%></td>
<td><%=resultset.getString("b.ServiceTag")%></td>
<td><%=resultset.getString("b.PONumber")%></td>
</tr>
</table>
<% } state.close(); }catch (SQLException e) { System.out.println(e.toString()); }catch (ClassNotFoundException e) { System.out.println(e.toString()); } %>
</center>
</body>
</html>