Using jsp to connect SavingAccount tutorial example

Hello
I have a question on the tutorial i do not know if this is the right place but here it is
I tried to change the SavingAccount EJB (j2eettutorial exmple chapter 24)and add a Web client to it. I modified the JSP which was used in the converter exmple to use savingsAccount Ejbs.
I have spent a week on this simple example, it compiles, and deployed without a problem but when i run it on the browser it says error 404 the page does not exist.
the exmple is only one Bean with two interfaces and one jsp page called index.jsp I am going mad, started to panic there is nothing wrong still why it does not work.
I packaged the bean and used /context root for jsp imported the bean in jsp give the resource ref inside the jsp ...
I do not understand what is the mestray behind this. is it because i only use one simple jsp? than what else should use to connect to ejb? can anyone help me please

the code for Ejb bean classe
package bookings;
import java.sql.*;
import javax.sql.*;
import java.util.*;
import java.util.Date;
import java.math.*;
import javax.ejb.*;
import javax.naming.*;
public class BookBean implements EntityBean {
    private final static String dbName = "java:comp/env/jdbc/BooksDB";
    private String ISBN;
    private String title;
    private String author;
    private String borrowedBy;
    private String dateDue;
    private EntityContext context;
    private Connection con;
     public String getISBN() {
        return ISBN;
    public String getTitle() {
        return title;
    public String getAuthor() {
        return author;
    public String getBorrowedBy() {
        return borrowedBy;
public String getDateDue() {
        return dateDue;
    public String ejbCreate(String ISBN, String title, String author,
        String borrowedBy, String dateDue) throws CreateException {
        try {
            insertRow(ISBN, title, author, borrowedBy, dateDue);
        } catch (Exception ex) {
            throw new EJBException("ejbCreate: " + ex.getMessage());
        this.ISBN = ISBN;
        this.title = title;
        this.author = author;
        this.borrowedBy = borrowedBy;   
        this.dateDue = dateDue;
        return ISBN;
    public String ejbFindByPrimaryKey(String primaryKey)
        throws FinderException {
        boolean result;
        try {
            result = selectByPrimaryKey(primaryKey);
        } catch (Exception ex) {
            throw new EJBException("ejbFindByPrimaryKey: " + ex.getMessage());
        if (result) {
            return primaryKey;
        } else {
            throw new ObjectNotFoundException("Row for      ISBN " + primaryKey +
                " not found.");
    public Collection ejbFindByTitle(String title)
        throws FinderException {
        Collection result;
        try {
            result = selectByTitle(title);
        } catch (Exception ex) {
            throw new EJBException("ejbFindByTitle " + ex.getMessage());
        return result;
    public Collection ejbFindByAuthor(String author)
        throws FinderException {
        Collection result;
        try {
            result = selectByAuthor(author);
        } catch (Exception ex) {
            throw new EJBException("ejbFindByAuthor: " + ex.getMessage());
        return result;
    public void ejbRemove() {
        try {
            deleteRow(ISBN);
        } catch (Exception ex) {
            throw new EJBException("ejbRemove: " + ex.getMessage());
    public void setEntityContext(EntityContext context) {
        this.context = context;
    public void unsetEntityContext() {
    public void ejbActivate() {
        ISBN = (String) context.getPrimaryKey();
    public void ejbPassivate() {
        ISBN = null;
    public void ejbLoad() {
        try {
            loadRow();
        } catch (Exception ex) {
            throw new EJBException("ejbLoad: " + ex.getMessage());
    public void ejbStore() {
        try {
            storeRow();
        } catch (Exception ex) {
            throw new EJBException("ejbStore: " + ex.getMessage());
    public void ejbPostCreate(String ISBN, String title, String author,
        String borrowedBy,String dateDue) {
    /*********************** Database Routines *************************/
    private void makeConnection() {
        try {
            InitialContext ic = new InitialContext();
            DataSource ds = (DataSource) ic.lookup(dbName);
            con = ds.getConnection();
        } catch (Exception ex) {
            throw new EJBException("Unable to connect to database. " +
                ex.getMessage());
    private void releaseConnection() {
        try {
            con.close();
        } catch (SQLException ex) {
            throw new EJBException("releaseConnection: " + ex.getMessage());
    private void insertRow(String ISBN, String title, String author,
        String borrowedBy, String dateDue) throws SQLException {
        makeConnection();
        String insertStatement =
            "insert into books values ( ? , ? , ? , ? )";
        PreparedStatement prepStmt = con.prepareStatement(insertStatement);
        prepStmt.setString(1, ISBN);
        prepStmt.setString(2, title);
        prepStmt.setString(3, author);
        prepStmt.setString(4, borrowedBy);
         prepStmt.setString(5, dateDue);
        prepStmt.executeUpdate();
        prepStmt.close();
        releaseConnection();
    private void deleteRow(String ISBN) throws SQLException {
        makeConnection();
        String deleteStatement = "delete from Books where ISBN = ? ";
        PreparedStatement prepStmt = con.prepareStatement(deleteStatement);
        prepStmt.setString(1, ISBN);
        prepStmt.executeUpdate();
        prepStmt.close();
        releaseConnection();
    private boolean selectByPrimaryKey(String primaryKey)
        throws SQLException {
        makeConnection();
        String selectStatement =
            "select ISBN " + "from Books where ISBN = ? ";
        PreparedStatement prepStmt = con.prepareStatement(selectStatement);
        prepStmt.setString(1, primaryKey);
        ResultSet rs = prepStmt.executeQuery();
        boolean result = rs.next();
        prepStmt.close();
        releaseConnection();
        return result;
    private Collection selectByTitle(String title)
        throws SQLException {
        makeConnection();
        String selectStatement =
            "select ISBN" + "from bo where title = ? ";
        PreparedStatement prepStmt = con.prepareStatement(selectStatement);
        prepStmt.setString(1, title);
        ResultSet rs = prepStmt.executeQuery();
        ArrayList a = new ArrayList();
        while (rs.next()) {
            String ISBN = rs.getString(1);
            a.add(ISBN);
        prepStmt.close();
        releaseConnection();
        return a;
    private Collection selectByAuthor(String author)
        throws SQLException {
        makeConnection();
        String selectStatement =
            "select ISBN from Books " +
            "where author = ?";
        PreparedStatement prepStmt = con.prepareStatement(selectStatement);
        prepStmt.setString(1, author);
        ResultSet rs = prepStmt.executeQuery();
        ArrayList a = new ArrayList();
        while (rs.next()) {
            String ISBN = rs.getString(1);
            a.add(ISBN);
        prepStmt.close();
        releaseConnection();
        return a;
    private void loadRow() throws SQLException {
        makeConnection();
        String selectStatement =
            "select title, author,borrowedBy, dateDue " +
            "from Books where ISBN = ? ";
        PreparedStatement prepStmt = con.prepareStatement(selectStatement);
        prepStmt.setString(1, this.ISBN);
        ResultSet rs = prepStmt.executeQuery();
        if (rs.next()) {
            this.title = rs.getString(1);
            this.author = rs.getString(2);
            this.borrowedBy=rs.getString(3);
            this.dateDue = rs.getString(4);
            prepStmt.close();
        } else {
            prepStmt.close();
            throw new NoSuchEntityException("Row for ISBN " + ISBN +
                " not found in database.");
        releaseConnection();
    private void storeRow() throws SQLException {
        makeConnection();
        String updateStatement =
            "update Books set title =  ? ," +
            "author = ? , borrowedBy = ? " + " dateDue = ?, where ISBN = ?";
        PreparedStatement prepStmt = con.prepareStatement(updateStatement);
        prepStmt.setString(1, title);
        prepStmt.setString(2, author);
        prepStmt.setString(3, borrowedBy);       
        prepStmt.setString(4, dateDue);
        prepStmt.setString(5, ISBN);
        int rowCount = prepStmt.executeUpdate();
        prepStmt.close();
        if (rowCount == 0) {
            throw new EJBException("Storing row for ISBN " + ISBN + " failed.");
        releaseConnection();
// end of BookBean the code for remot interface
package bookings;
import java.rmi.RemoteException;
// Java extension packages
import javax.ejb.*;
public interface Book extends EJBObject {
    public void getISBN() throws RemoteException;
    public String getTitle() throws RemoteException;
    public String getAuthor() throws RemoteException;
    public String getBorrowedBy() throws RemoteException;
    public String getDateDue() throws RemoteException;
}the codes for home // BookHome.java
// BookHome is the home interface for entity EJB Book.
package bookings;
import java.util.Collection;
import java.rmi.RemoteException;
// Java extension packages
import javax.ejb.*;
public interface BookHome extends EJBHome {
    // create Book EJB using given book details
   public Book create( String ISBN, String title, String author,
        String borrowedBy, String dateDue)  throws RemoteException, CreateException;
   // find Book with given ISBN
   public Book findByPrimaryKey( String isbn )
      throws RemoteException, FinderException;
   // find all Books
   public Collection findAllBooks()
      throws RemoteException, FinderException;
   // find Books with given title
   public Collection findByTitle( String title )
      throws RemoteException, FinderException;
     // find Books with given author
    public Collection findByAuthor(String author)
        throws FinderException, RemoteException;
  // find Books with given author
    public Collection findBorrowedBy(String borrowedBy)
        throws FinderException, RemoteException;
  }the code for index.jsp to use the ejb which i get this error messgae when i run it
HTTP 404 - File not found
Internet Explorer i can tell you that i have deployed 8 times with changes
<%@ page import="bookings.*, javax.ejb.*, javax.naming.*, javax.rmi.PortableRemoteObject, java.rmi.RemoteException" %>
<%!
   private Book book = null;
   public void jspInit() {
      try {
         InitialContext ic = new InitialContext();
         Object objRef = ic.lookup("java:comp/env/ejb/TheBooking");
         BookHome home = (BookHome)PortableRemoteObject.narrow(objRef, BookHome.class);
         book = home.create();
      } catch (RemoteException ex) {
            System.out.println("Couldn't create book bean."+ ex.getMessage());
      } catch (CreateException ex) {
            System.out.println("Couldn't create book bean."+ ex.getMessage());
      } catch (NamingException ex) {
            System.out.println("Unable to lookup home: "+ "TheBook "+ ex.getMessage());
   public void jspDestroy() {   
         book = null;
%>
<html>
<head>
    <title>Book</title>
</head>
<body bgcolor="white">
<h1><b><center>Book</center></b></h1>
<hr>
<p>Enter an ISBN:</p>
<form method="get">
<input type="text" name="amount" size="25">
<br>
<p>
<input type="submit" value="Submit">
<input type="reset" value="Reset">
</form>
<%
    String isbn = request.getParameter("isbn");
%>
   <p>
   <%= isbn %> the book isbn is  <%= book.getISBN() %> 
   <p>
   <%= title %> the book title <%= book.getTitle() %> 
</body>
</html>

Similar Messages

  • Using JSP to connect to an Access Database

    I need help on using JSP to connect to an Access database.
    This is the code I currently have connecting to a mySQL DB. I need to change it to connect to an Access DB. The reason I am switching DB's is because mySQL is no longer going to be carried by my host.
    Here is the code:
    <html>
    <head>
    <basefont face="Arial">
    </head>
    <body>
    <%@ page language="java" import="java.sql.*" %>
    <%!
    // define variables
    String UId;
    String FName;
    String LName;
    // define database parameters
    String host="localhost";
    String user="us867";
    String pass="jsf84d";
    String db="db876";
    String conn;
    %>
    <table border="2" cellspacing="2" cellpadding="5">
    <tr>
    <td><b>Owner</b></td>
    <td><b>First name</b></td>
    <td><b>Last name</b></td>
    </tr>
    <%
    Class.forName("org.gjt.mm.mysql.Driver");
    // create connection string
    conn = "jdbc:mysql://" + host + "/" + db + "?user=" + user + "&password=" +
    pass;
    // pass database parameters to JDBC driver
    Connection Conn = DriverManager.getConnection(conn);
    // query statement
    Statement SQLStatement = Conn.createStatement();
    // generate query
    String Query = "SELECT uid, fname, lname FROM abook";
    // get result
    ResultSet SQLResult = SQLStatement.executeQuery(Query);
         while(SQLResult.next())
              UId = SQLResult.getString("uid");
              FName = SQLResult.getString("fname");
              LName = SQLResult.getString("lname");
              out.println("<tr><td>" + UId + "</td><td>" + FName + "</td><td>" + LName
    + "</td></tr>");
    // close connection
    SQLResult.close();
    SQLStatement.close();
    Conn.close();
    %>
    </table>
    </body>
    </html>
    Thank You,
    Josh

    <%@ page language="java"%>
    <html>
    <head>
    <title>
    First Bean
    </title>
    <%@ page import="java.sql.*" %>
    </head>
    <body>
    <p>
    <%!
    Connection con;
    Statement st;
    ResultSet rs;
    String userid;
    String password;
    %>
    <%!public void db(JspWriter out)
    try{
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    con=DriverManager.getConnection("jdbc:odbc:phani");
    catch(Exception e){}
    try{
    st=con.createStatement();
    rs=st.executeQuery("SELECT * FROM login");
    while(rs.next())
    userid=rs.getString("userid");
    password=rs.getString("password");
    out.println(userid);
    out.println("</br>");
    out.println(password);
         out.println("</br>");     
    }catch(Exception e){}
    try{
    con.close();
    }catch(Exception e){}
    %>
    <%db(out);%>
    </p>
    </body>
    </html>
    phani is dsn name
    login is table name
    Good luck
    phani

  • How to create Reports and Forms using JSP

    Hi,
    How to create reports using JSP. And how many types of reports can be created using JSP.Can anyone explain with example please.
    Thanks,
    Vijayalakshmi.M

    Here is some code that creates xml for any SQL that returns a ResultSet. Note this uses my default out-of-the-box XML template, but you can quickly create and use your own templates to generate xml to look anyway you desire.
    FormattedDataSet fds=FormattedDataSet.createInstance();
    Map miscData=new HashMap();
    map.put("rootElement", "musicgroups");
    String xml=fds.getFormattedDataSet("select * from groups", miscData, "xml1");
    String xml has the value:
    <musicgroups>
    <row rowID='1'>
      <group_id>1</group_id>
      <group_name>Rolling Stones</group_name>
      <type>Rock</type>
    </row>
    <row rowID='2'>
      <group_id>2</group_id>
      <group_name>Beatles</group_name>
      <type>Rock</type>
    </row>
    <row rowID='3'>
      <group_id>3</group_id>
      <group_name>Led Zepplin</group_name>
      <type>Rock</type>
    </row>
    </musicgroups>steve -
    http://www.fdsapi.com - The easiest way to generate dynamic HTML and XML
    http://www.jamonapi.com - A performance tuning and scalability measuring API

  • How can I upload an image using JSP in database(MySQL)

    I have to develop an application in which users can register themselve by filling up thier information(name, address) etc along with their photo.
    Storing nam etc. is simple but i am unable to upload photo using JSP.

    Here are lot of examples: http://www.google.com/search?q=jsp+file+upload
    Or if you actually have implemented something which doesn't work as expected, then please ask specific questions.

  • With the left panel, trying to use the Presets, in the tutorial to the left of the commands there are square icons, for example "Lightroom B

    With the left panel, trying to use the Presets, in the tutorial to the left of the commands there are square icons, for example “Lightroom B & W Presets”. On my program they are arrowheads pointing to the right. When I click on any Preset, it does not work.
    Also, Right Panel, Color, White Balance, “As Shot” only has 2 options (auto & custom) vs. tutorial that has 9 options.

    You are not supposed to connect a pair of speakers(as in left and right in a stereo pair)to two separate out jacks on the sound card.the place on the card where headphones/speakers with the mini jack goes is the right place.

  • How can I  connect to SQL server database thru local network by using JSP?

    I'm currently doing a project by using JSP..And I need to display record from the SQL Server database in our school's local network. May I know how can I do that? How can I write the code so that I can able to access the SQL Server databsase Throught school's network by using JSP? Please tell me step by step how can I do that. I'm using Tomcat 4.1 as Web Server. And I had J2SE and J2EE installed in my computer.

    first you have to establish a ODBC DSN on your computer,
    that connects to the database...you can do that from your control pannel.
    i assume that the TOMCAT server is residing on your computer....(if the webserver is in other computer then you would have to create a System DSN on the data sources ODBC option in the settings>control pannel of that machine)
    then you can use that DSN name to connect to the data base from the class file....for further assistance on how to create the class that access the tutorials in sun site.
    regards
    G

  • PLEASE REPLY ASAP.Unbale to connect to oracle data base using JSP.

    hi,
    I am not able to connect to oracle data base using JSP. PFB the code and out put.
    <html>
    <!--Importing the Packages-->
    <%@ page import = "java.sql.*" %>
    <body>
    <%
    try
         out.println("hi<br>");
    Connection conn = DriverManager.getConnection("jdbc:oracle:oci:@xxx.xxx.xx.xxx:xxxx:flstr800","user","paswordd");
         out.println("connected<br>");
    catch (SQLException e)
    out.println("ERROR: failed to connect!");
    out.println("ERROR: " + e.getMessage());
    e.printStackTrace();
    return;
    %>
    </body>
    </html>
    OUTPUT:
    hi
    ERROR: failed to connect! ERROR: No suitable driver found for jdbc:oracle:oci:@host:port
    Please guide me on this issue.
    Edited by: user10997061 on Apr 10, 2009 4:27 AM

    I definitely do not know much about JSP but
    http://www.oracle.com/technology/tech/java/sqlj_jdbc/htdocs/jdbc_faq.html
    indicates
    <quote>
    This URL connects to the same database using the the OCI driver and the SID inst1 without specifying the username or password.
    jdbc:oracle:oci:@myhost:1521:inst1
    <quote>
    I do not see the port information in your connect string. Is that an issue?

  • Using a single connection for jsp, servlets and classes

    Hi! I'm building a web site that uses JSP, Servlets and some classes. I use database access in all my pages. I want to open a connection and use it for all the pages while the user is in my site, so I don't need to open a connection with every new jsp or servlet page. My software must be capable of connection with various databases, like SQLServer, Oracle, Informix, etc... so the solution must not be database (or OS or web server) dependant.
    Can you help me with this? Some ideas, links, tips? I'll REALLY appreciate your help.
    Regards,
    Raul Medina

    use an initialiation servlet with pooled connection which can be accessed as sesssion object.
    Abrar

  • Error due to accessing database connection using jsp

    Hi,
    I have an error, during accessing a datbase using jsp:useBean from jsp.Urgent i need this one
    my source code is
    DbBean.java
    package SQLBean;
    import java.sql.*;
    import java.io.*;
    public class DbBean implements java.io.Serializable{
    private String dbDriver = "sun.jdbc.odbc.JdbcOdbcDriver";
    private Connection dbCon;
    public DbBean(){
    super();
    public boolean connect() throws ClassNotFoundException,SQLException{
    Class.forName(dbDriver);
    dbCon = DriverManager.getConnection("jdbc dbc:mybean","","");
    return true;
    public void close() throws SQLException{
    dbCon.close();
    public ResultSet execSQL(String sql) throws SQLException{
    Statement s = dbCon.createStatement();
    ResultSet r = s.executeQuery(sql);
    return (r == null) ? null : r;
    public int updateSQL(String sql) throws SQLException{
    Statement s = dbCon.createStatement();
    int r = s.executeUpdate(sql);
    return (r == 0) ? 0 : r;
    database.jsp
    <HTML>
    <HEAD><TITLE>DataBase Search</TITLE></HEAD>
    <BODY>
    <%@ page language="Java" import="java.sql.*" %>
    <jsp:useBean id="db" scope="application" class="SQLBean.DbBean" />
    <jsp:setProperty name="db" property="*" />
    <center>
    <h2> Results from </h2>
    <hr>
    <br><br>
    <table>
    <%
    db.connect();
    ResultSet rs = db.execSQL("select * from employ");
    int i = db.updateSQL("UPDATE employ set fname = 'hello world' where empno='000010'");
    out.println(i);
    %>
    <%
    while(rs.next()) {
    %>
    <%= rs.getString("empno") %>
    <BR>
    <%
    %>
    <BR>
    <%
    db.close();
    %>
    Done
    </table>
    </body>
    </HTML>
    The error like this
    org.apache.jasper.JasperException: Unable to compile class for JSPNote: sun.tools.javac.Main has been deprecated.
    error: Invalid class file format in C:\Program Files\Apache Tomcat 4.0\webapps\muthu\WEB-INF\classes\SQLBean\DbBean.class. The major.minor version '49.0' is too recent for this tool to understand.
    An error occurred at line: 7 in the jsp file: /database.jsp
    Generated servlet error:
    C:\Program Files\Apache Tomcat 4.0\work\localhost\muthu\database$jsp.java:65: Class SQLBean.DbBean not found.
    SQLBean.DbBean db = null;
    ^
    An error occurred at line: 7 in the jsp file: /database.jsp
    Generated servlet error:
    C:\Program Files\Apache Tomcat 4.0\work\localhost\muthu\database$jsp.java:68: Class SQLBean.DbBean not found.
    db= (SQLBean.DbBean)
    ^
    An error occurred at line: 7 in the jsp file: /database.jsp
    Generated servlet error:
    C:\Program Files\Apache Tomcat 4.0\work\localhost\muthu\database$jsp.java:73: Class SQLBean.DbBean not found.
    db = (SQLBean.DbBean) java.beans.Beans.instantiate(this.getClass().getClassLoader(), "SQLBean.DbBean");
    ^
    4 errors, 1 warning
    Anybody help me?
    Thanx in advance

    Your code is ok . The problem is in java version witch you use to compile the DbBean class . I think you are using java 1.5 try to change to 1.4 compile and run again should help .

  • Can I connect my Mac (Mac OS X) with other machine (Windows OS) on same LAN using telnet in terminal? For example, telnet ip address of other machine

    Can I connect my Mac (Mac OS X) with other machine (Windows OS) on same LAN using telnet in terminal?
    For example, telnet <ip address of other machine>
    I m a networking student and I have learned to connect 2 machines on Red hat Linux OS on same Ethernet LAN which has same subnet mask. As Mac OS X is also a linux based OS I m trying to connect my Mac with my friends windows based machine using telnet <ip address of his machine>. However, I get a message "unable to connect to remote host".
    Can anyone please tell me is this the problem because of different OS or it is something different!
    Please reply...it will of great help..

    The machine you're trying to connect to needs a Telnet server running on it - telnetd listening on port 23 (usually).
    Incidentally, Mac OS X is not a Linux based OS, it is based on BSD Unix.

  • Error when Connect to Oracle using JSP

    DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver()); There is no problem with this code in Java, but when i used it in JSP, the error occured.
    java.lang.ClassNotFoundException: oracle.jdbc.OracleDriver
    I am using JRUN Web Server, i don't know how to Configure JRUN to use JSP with Oracle.

    the problem is that your JDBC driver is not in the classpath of your servlet. Add the jar file to the WEB-INF\lib folder of your web application.
    i don't know how to Configure JRUNSorry, but in order to achieve anything, you'll have to RTFM.

  • JSP DB Connection

    I wanted to connect to an oracle database using JSP. I've successfully done this. However, it looks like I will now have 1 giant file (jsp) with the db connection code included in it, and I think this is messy. So... I'd like to have a separate Java file which allows me to connect to the database, then somehow use this in the JSP file? I imagine the Java file would be compiled only once and would sit on the server while being accessed via the JSP file.
    Is this possible? If so, any tips?
    Thanks.

    A bean is the preferred way to do it.
    However, a more simpler method is simply put all of your database connection stuff in a standalone object, compile that object into a class file, place the class file in the appropriate directory, and simply invoke it as needed.
    For example...
    I have a class db that was created in db.java, with a constructor, various methods, and so on.
    I place db.class in the classes directory of my Servlet Engine.
    In my jsp page, I do...
    <%@ page import "db" %>
    and eventually...
    <%
    db myDatabaseConnection = new db;
    db.connect();
    resultSet results = db.executeQuery( query );
    db.close();
    %>
    I think there should be some examples in your reference book (or tutorial). Simply look up importing other classes into your application. Please don't use mine, as there are some minor flaws and potential for trouble, but it should be good enough to give you an idea of what you can do.

  • Dynamic select using jsp?

    grrrrr............ok so I'm kinda new to this, and just a little frustrated. I'm gonna ramble here, so any time I sound like I don't know what I'm talking about it 's because I don't..correct me. I want to include a bean in a jsp which will buil d a dynamic select box on the fly. That is, connect to an LDAP db and place each value returned in the query in a select box. Now, I can compile and run the bean in my IDE and watch the output in the console. It's correct because I see "<select><option value = hall>hall....</select>". In the buildSelectBox() method I'm using System.out.println to display each line of my select box (is that right?). Now, when I copy the .class file over to the server I was initially getting an error because the bean wasn't found. I resolved that by properly compiling the bean in a package. Problem is that if I call the bean.buildSelect() method in the .jsp nothing comes back. The page is left blank. What in the world is that about? Can someone push me toward a tutorial that can push me in the right direction or sumthin? Why am I having so much trouble with this? Should I be building the select on the jsp?
    regards,
    mat

    Hi!
    If i understand you correctly :-) you are doing not very right things. I don't want it to seem like I'm going to teach you, but:
    The Bean that has buildSelect() method is not a bean at all. Usualy Beans contain getter/setters and accumulate data. If you want to build html code dynamicaly then you should use servlets(Which is not very flexible in your situation, I think), not JSPs. And if you are using JSPs then you have to make Tag which will do this everything.
    Other way is to use Struts framework which is very good and flexible for building web applications - it has it's own tags for many cases. You can make loops in JSPs, use beans and all that stuff.
    Guys will correct me if I missed something.
    Good luck

  • How to upload an html file using jsp and jdbc

    Hi,
    im trying to upload an html page using JSP and jdbc. but of no success.
    my aim is to keep some important html pages in the database.the file size can vary.the file has to be selected from a local machine (through the browser) and uploaded to a remote machine(where the databse resides).
    any help/sample code or pointer to any helpful link is appreciated.
    thanks in advance
    javajar2003

    When uploading a file, I use a byte array as a temporary buffer..
    So, you should then be able to store the byte array in the
    database as binary data.
    example>
    //Temporary Buffer To Store File
    byte[] tmpbuffer = new byte[860];
    //Some Code To Upload File...
    //File Should Now Be In Byte Array
    //Get DB Connection and execute Prepared Statement
    Connection con=//GET DB CONNECTION;
    String sql=insert into TABLE(page) values(?);
    PreparedStatement ps=con.prepareStatement(sql);
    ps.setBytes(1,tempbuffer);
    ps.executeUpdate();
    //Close PS and Free DB Connection
    ..... and this method looks like you dont even have
    to store the file in a byte array, you can just give
    it the input stream.
    ps.setBinaryStream(int, inputStream, int);
    You may have to make several attempts at this. I have
    uploaded a file and temporarily stored it in a byte array,
    but have never from there stored it in the DB as binary
    data.. but this looks like it'll work.
    Good Luck!

  • Why do we use jsp instead of servlet

    why do we use jsp instead of servlet

    Hi,
    I am and web/Java developer and have used a mixture of JSPs and servlets. I use JSPs for my actual web pages. Whether they are displaying dynamic database driven content or simple pages doing nothing but password protecting.
    I tend to separate other reusable code into servlets, like database connections and business logic.
    For example: I have worked on a mortgage site and there quite a lot that goes into calculating a monthly payment and ARP. These calculations will not change (only values I send to them will) therefore I do this type of coding in a servlet.
    Cheers
    Mark
    :o)

Maybe you are looking for