Showing posts with label jsp. Show all posts
Showing posts with label jsp. Show all posts

Friday, 11 January 2013

Print cluster member hostname from with a JSP


<html>

<head>
</head>
<body>
<%@ page import="java.net.InetAddress" %>
This is a test from Hello.jsp<br>
<%
    InetAddress ia = InetAddress.getLocalHost();
    out.println("hostname  " + ia.getHostName() +  "<br>");
%>
</body>
</html>


Using JDBC within a JSP

The code below is taken from http://www.devisland.net/help/jdbc_jsp.shtml with thanks

<HTML>

       <HEAD>
               <TITLE>DB Test</TITLE>
       </HEAD>

       <BODY>
               <%@ page language="java" import="java.sql.*,javax.naming.*,javax.sql.*" %>
               <%
              DataSource ds = null;
              Connection c = null;
              Statement Stmt = null;
              ResultSet RS = null;                                                                                    
              try{
                  Context initCtx = new InitialContext();
                  ds = (DataSource) initCtx.lookup("java:comp/env/jdbc/db_user");
                  c = ds.getConnection();
                  out.println("querying database...<br>");
                  Stmt = c.createStatement();
                  RS = Stmt.executeQuery("SHOW tables");
                  while (RS.next()) {
                      out.println(RS.getString(1)+"<br>");
                  }
              }
              catch(Exception e){
                  out.println("ERROR! "+e.getMessage());
              }
              finally{
                  try{
                      if(RS != null){
                          RS.close();
                      }
                      if(Stmt != null){
                          Stmt.close();
                      }
                      if(c != null){
                          c.close();
                      }
                  }
                  catch(Exception e2){
                      out.println("Unable to close connection: "+e2.getMessage());
                  }
               }
               %>
       </BODY>
</HTML>


---

Thursday, 10 January 2013

Dropping a JSP into an existing WebApp



I'll use IBM's WebSphere Perf Servlet as an example...

Placing hello.jsp in /opt/bpm/profiles/profile_name/installedApps/cell_name/perfServletApp.ear/perfServletApp.war allows this URL to be called
http://<host>:<port>/wasPerfTool/hello.jsp