Using a servlet in a jsp

Hi, I have recently been having problems with embedding a servlet within a JSP. I have attempted to do this by using a frame within the JSP and using JSP include tags however, nothing seems to display. The reason why I want to do this is because I need to take advantage of servlet persistence which JSPs do not have, plus, I want to use the JSP to refresh the page produced by the servlet every so often using AJAX.
Any ideas? Thanks,
--R                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

A JSP becomes a pure servlet on compilation. What persistence are u looking in a JSP ?
One reason you do not get anything is I am not tried this but I dont think its going to interpret the servlet code very well in the JSP page.
An include JSP tag includes another jsp/file inline and not sure if he can do a servlet there ?

Similar Messages

  • Problem for getting the real path using one servlet and one jsp page

    I have one tomcat machine and several virtual domains. Eahc virtual domain has one realpath in the disc.
    I am using one servlet and one jsp page for using this servlet.
    my purpose is to load, using the servlet , the real path for the domains (eahc domain has its path).
    for this i make this:
    the servlet code is this:
    package utils.ticker;
    import java.io.*;
    import java.io.File;
    import java.io.IOException;
    import java.net.*;
    import java.util.*;
    import java.text.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.Filter;
    import javax.servlet.FilterChain;
    import javax.servlet.FilterConfig;
    import javax.servlet.ServletContext;
    import javax.servlet.ServletException;
    import javax.servlet.ServletRequest;
    import javax.servlet.ServletResponse;
    public class Edicion extends HttpServlet{
    public Edicion() {
    public String cc(){
    ServletContext myContext= getServletContext();
    String abspath = myContext.getRealPath("/");
    //here i want to return the real path
    return abspath;
    public static void main(String args[]){
    and the jsp page is:
    <%@ page import="utils.ticker.*" %>
    <jsp:useBean id="tick" class="utils.ticker.Edicion" scope="session"/>
    <html><head><body>
    <%
    tick.cc();
    %>
    </body></head></html>
    But this produces one error, NullPointerException and dont shows me the real path.
    Can anyone help me?
    thanks

    i have put this into one sevlet:
    package utils.ticker;
    import javax.servlet.ServletContext;
    public class Edicion{
    private ServletContext myContext;
    public Edicion(ServletContext myContext) {
    this.myContext = myContext;
    public String getCC(){
    return myContext.getRealPath("/");
    and in the jsp page this:
    <%@ page contentType="text/html; charset=iso-8859-1" language="java" import="java.sql.*"%>
    <%@ page import="utils.ticker.*" %>
    <jsp:useBean id="tick" class="utils.ticker.Edicion" scope="session"/>
    <html><head><body>
    <%=tick.getCC()%>
    </body></head></html>
    but appear this error in the tomcat.
    Can you, please, help me. i am trying to solve this during one week and i am desesperate.
    Thanks.
    ERROR:
    HTTP Status 500 -
    type Exception report
    message
    description The server encountered an internal error () that prevented it from fulfilling this request.
    exception
    org.apache.jasper.JasperException: class utils.ticker.Edicion : java.lang.InstantiationException: utils.ticker.Edicion
         at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:248)
         at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:295)
         at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
         at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
         at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
         at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:260)
         at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
         at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
         at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
         at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
         at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
         at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
         at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
         at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2415)
         at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)
         at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
         at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:170)
         at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
         at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:172)
         at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
         at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
         at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
         at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)
         at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
         at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
         at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
         at org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:223)
         at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:432)
         at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:386)
         at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:534)
         at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:530)
         at java.lang.Thread.run(Thread.java:536)
    root cause
    javax.servlet.ServletException: class utils.ticker.Edicion : java.lang.InstantiationException: utils.ticker.Edicion
         at org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:533)
         at org.apache.jsp.pruebas_jsp._jspService(pruebas_jsp.java:72)
         at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:137)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
         at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:204)
         at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:295)
         at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
         at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
         at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
         at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:260)
         at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
         at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
         at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
         at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
         at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
         at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
         at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
         at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2415)
         at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)
         at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
         at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:170)
         at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
         at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:172)
         at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
         at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
         at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
         at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)
         at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
         at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
         at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
         at org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:223)
         at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:432)
         at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:386)
         at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:534)
         at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:530)
         at java.lang.Thread.run(Thread.java:536)
    Apache Tomcat/4.1.18

  • When is it appropriate to use a servlet in a JSP/JSF environment?

    I have inherited a fairly old JSP-based application. I know that I need to update its technologies, in particular the use of AJAX so that I don't need to keep refreshing the page each time I want more data from the server. The problem is that I don't know a great deal about other technologies. There seem to be so many conflicting opinions about the way to go regarding servlets and JSP and JSF (and possibly JavaBeans). I am probably going to start using JSF and AJAX. I mention this to give you some background info. My real question is: when is best/appropriate to use a servlet? From what I have seen I do not want to use a servlet for generating HTML output - that seem just so last decade! But do they still have a good use over more modern technologies? Also, when is it appropriate to use JavaBeans? Are JavaBeans a thing of the past (or just plain inappropriate) for web applications?
    Regards,

    I suggest going to the bookstore and looking for a book on JSF and reading it cover to cover. It may tell you where servlets come into the picture (if at all). I suggest paying attention to MVC design that it discusses, and working through the examples before working on your project (assuming you have the time). Then creating a simple project and refactor it over and over to meet MVC.
    For your project, I suggest just doing ONE JSF page (and its underlying database access) and refactor it over and over again (MVC) before doing the other JSF pages. This way, you dont have to refactor 34 JSF pages to correct the same mistake appearing in all the pages (saves a LOT of time).
    I don't know enough about AJAX to really comment on it. However, I would ask myself if refreshing the JSF page is really enough of a concern for your end-users to make it worth while to use AJAX on this project.

  • Problem with displaying BLOB images on JSP page using a servlet

    hi. I have a big problem with displaying BLOB images using JSP. I have a servlet that connects to the oracle database, gets a BLOB image , reads it, and then displays it using a BinaryStream. The problem is , this works only when i directly call that servlet, that is http://localhost:8080/ImageServlet. It doesn't work when i try to use that servlet to display my image on my JSP page (my JSP page displays only a broken-image icon ) I tried several coding approaches with my servlet (used both Blob and BLOB objects), and they work just fine as long as i display images explicitly using only the servlet.
    Here's what i use : ORACLE 10g XE , Eclipse 3.1.2, Tomcat 5.5.16 , JDK 1.5
    here is one of my image servlet's working versions (the essential part of it) :
                   BLOB blob=null;
              rset=st.executeQuery("SELECT * FROM IMAGES WHERE ID=1");
              while (rset.next())
                   blob=((OracleResultSet)rset).getBLOB(2);
              response.reset();
              response.setContentType("image/jpeg");
              response.addHeader("Content-Disposition","filename=42.jpeg");
                    ServletOutputStream ostr=response.getOutputStream();
                   InputStream istr=blob.getBinaryStream(1L);
                    int size=blob.getBufferSize();
              int len=-1;
                    byte[] buff = new byte[size];
                         while ((len=istr.read( buff ))!=-1 ) {
                   ostr.write(buff,0,len);
             response.flushBuffer();
             ostr.close(); and my JSP page code :
    <img src="/ImageServlet" border="0"  > If you could just tell me what i'm doing wrong here , or if you could show me your own solutions to that problem , i would be very greatful ,cos i'm realy stuck here , and i'm rather pressed for time too. Hope someone can help.

    I turns out that it wasn't that big of a problem after all. All i had to do was to take the above code and place it into another JSP page instead of into a servlet like i did before. Then i just used that page as a source for my IMG tag in my first JSP. It works perfectly well. Why this doesn't work for servlets i still don't know, but it's not a problem form me anymore . Ofcourse if someone knows the answer , go ahead and write. I would still appriceatte it.
    here's the magic tag : <img src="ImageJSP.jsp" border="0"  > enjoy : )

  • Why do we use both servlets & jsps in developing  an application ?

    why do we use both servlets & jsps in developing an application & not only jsps

    Hi,
    It's a pure question of design : Some like it jsp to jsp and others servlet to jsp. It's up to you to decide and it depends of the complexity of your application.
    But the best design is the MVC (servlet and jsp working together) because it helps you separate presentation from logic. It also helps you better maintain you code.
    You can have more info in javaworld.com.
    Good luck
    touco

  • How to use JNDI lookup from a JSP

    Hello,
    I know I should not be doing this (writing the lookup code in a JSP) but have to do it for some reasons.
    I am using this code in my JSP:
    try
         Context ctx = new InitialContext();
         dataSource = (DataSource)ctx.lookup("jdbc/mybillingora");
         conn = dataSource.getConnection();
         statement = conn.createStatement();
    catch(Exception excep)
    Is this code enough for a JNDI look up?? When I use this code, I get an exception:
    "javax.naming.NameNotFound exception:jdbc/mybillingora"
    Do I need to do something else??
    Why do we use :
    Properties env = new Properties();
    env.put(Context.INITIAL_CONTEXT_FACTORY,
    "<some_context_factory>");
    env.put(Context.PROVIDER_URL, PROVIDER_URL);
    env.put(Context.SECURITY_PRINCIPAL, JNDI_USER);
    env.put(Context.SECURITY_CREDENTIALS, JNDI_PWD);
    InitialContext = new InitialDirContext(env);
    where JNDI_USER is the userid If ACL is configured at the JNDI server
    where JNDI_PWD is the password If ACL is configured at the JNDI server
    Context.INITIAL_CONTEXT_FACTORY is the initial Context factory and depends on ur JNDI service provider.
    PROVIDER_URL is the url of the JNDI server containing protocol/ip/port
    do i need to use this??
    would appreciate your help on this....
    Thanks

    If Tomcat is your servlet/JSP engine, they have a nice bit about how to do it:
    http://jakarta.apache.org/tomcat/tomcat-4.1-doc/jndi-datasource-examples-howto.html
    MOD

  • Tomcat 6 – Calling a  Java Servlet from a JSP Page

    Below is a very simple JSP Page that calls a Java Servlet. The question is given Tomcat security constraints, is it possible to call a servlet from a JSP and get the correct output without getting an error message? If so, how would you code the web.xml file?
    c:\apache-tomcat-6.0.18
    Under conf
    catalina
    localhost
    HelloWorldExample.xml is directly under localhost
    The application would have this directory structure:
    webapps
    HelloWorldExample
    hello.jsp is directly under HelloWorldExample
    Under HelloWorldExample
    src
    WEB-INF
    classes
    Under classes
    jservlets
    HelloWorld.java is in src folder
    HelloWorld.class is in jservlets folder
    HelloWorldExample.xml
    <Context path="/HelloWorldExample" docBase="HelloWorldExample" debug="0"
          reloadable="true" crossContext="true">    
    </Context>**************************
    hello.jsp
    <HTML>
    <HEAD>
    <TITLE>Hello</TITLE>
    </HEAD>
    <BODY>
    <FONT SIZE="4">
    <P>
    Please enter your name:
    <FORM 
       METHOD="Post"
       ACTION="servlet/jservlets.HelloWorld">
    <TABLE BORDER="3" CELLPADDING="1" WIDTH="100%" ALIGN="CENTER">
    <TR>
        <TD><B>Name:</B></TD>
        <TD><INPUT TYPE="text" NAME="Name" VALUE="" SIZE="65"> </TD>      
    </TR>
    </TABLE>
    <P>
    <INPUT TYPE="SUBMIT" VALUE="Submit">
    </FORM>
    </FONT>
    </BODY>
    </HTML>******************
    HelloWorld.java
    package jservlets;
    import java.io.*;
    import java.util.Date;
    import java.util.*;
    import java.text.*;
    import java.sql.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    public class HelloWorld extends HttpServlet
       PrintWriter out;
       PrintWriter err; 
       String strName;
    public void displayMessage(HttpServletRequest request, HttpServletResponse response)
          throws Exception
             try
                if (!strName.equals("") && strName != null)
                   out.println("Hello " + strName + "" + "<P>");
                    out.println("Hello World" + "<P>");
                else
                    out.println("Hello World" + "<P>");
            catch (Exception e)
                out.println("Exception: Could not display message." + "<P>");
                err.println (e.getMessage () ) ;
                out.println("<P>");
    public void doPost(HttpServletRequest request, HttpServletResponse response)
               throws ServletException, IOException
          try
               response.setContentType("text/html"); 
               out = response.getWriter();
               err = response.getWriter();
               strName = request.getParameter("Name").trim();
               out.println("<html><head><title>");        
              out.println("</title></head><body>");
               out.println("<FORM");
               out.println("METHOD=POST");
               out.println("ACTION=http://localhost:8080/HelloWorldExample/hello.jsp>");
             out.println("<TABLE ALIGN='RIGHT'>");
             out.println("<TR>");
             out.println("<TD>");          
               out.println("<INPUT TYPE=\"SUBMIT\" VALUE=\"Hello World Page\";>");
               out.println("</INPUT>");
              out.println("</TD>");
             out.println("</TR>");
             out.println("</TABLE>");
             out.println("</FORM>");
             out.println("<BR CLEAR='all'>");
               out.println("<P>");        
               displayMessage(request, response);
               out.close();
             out.println("</body></html>");               
           catch(Throwable e)
              e.printStackTrace();
          public void doGet(HttpServletRequest request, HttpServletResponse response)
             throws ServletException, IOException
             doPost(request, response);
    web.xml
    <servlet>
          <servlet-name>HelloWorld</servlet-name>
          <servlet-class>jservlets.HelloWorld</servlet-class>
    </servlet>  
    <servlet-mapping>
            <servlet-name>HelloWorld</servlet-name>
            <url-pattern>/servlet/HelloWorld</url-pattern>
    </servlet-mapping>      ******************************
    HelloWorld.java can be compiled by using javac.
    Once compiled, HelloWorld.class would be moved to the jservlets folder.
    FYI, coding the above url-pattern results in:
    HTTP Status 404
    The requested resource (/HelloWorldExample/servlet/jservlets.HelloWorld) is not available
    The following url-pattern in the web.xml file permits the servlet to be executed but results in a null pointer exception:
    <servlet-mapping>
            <servlet-name>HelloWorld</servlet-name>
            <url-pattern>/ </url-pattern>
    </servlet-mapping>      **************************************************
    Robin

    This problem was resolved.
    In hello.jsp
    ACTION="servlet/jservlets.HelloWorld">
    was replaced with
    ACTION="servlet/HelloWorld">
    Robin

  • Should I use a servlet? - please help

    Hi,
    This is my problem:
    I have a class (say, DBClass) that connects to the database - it has general functions for insertion, updation, and deletion.
    I have some other classes that use the DBClass to perform insert, update, delete operations on different tables.(e.g., User.java is the class that uses DBClass to add users to the UserMaster table)
    Now, I have a JSP that has a form (to accept user information). Is it right in instaniate a User object in the jsp itself, and call the addUser method (which will use the 'insert' method in DBClass and add it to the database), or will it be right to post the data to a servlet, and do the whole thing there?
    Which is the right way to do it?
    Please help. I am new to the JSP technology..
    Thank you,
    sangita

    Hi sangita,
    It is always recommended that for insertion in the database, u should use a Servlet and for retrieval of data, u should use a Java bean. U can write a DBClass, where u will write one method for returning the database connection and another for closing the connection. These methods u can access from your servlet as well as your bean.
    Hope it will help. Let me know.
    atanu

  • Using normal classes in a JSP

    I have written a library of classes for use in a standard application. In a completely separate project I need to use these classes in a JSP page. Under %tomcat/webapps/myproject is the JSP file. Where do I place the "normal" class files and how do I reference them in the JSP page? Do I need to import them or add them to the classpath and should they be pre-compiled ?
    All help most appreciated
    Thanks
    Bob

    Where do I place the "normal" class files and how do
    I reference them in the JSP page?Just like you use any other class in a JSP.
    Do I need to import them or add them to the classpath and should they be pre-compiled ?Yes, yes and yes. The first thing is something you need to do for your stuff to compile (technically, you don't need to do it, but it's better than always using the fully qualified class names in the code). The second is something the servlet container will do for you when you deploy your WAR. The this is something you need to do with classes anyway. You don't need to do it for JSPs because the container will do it later, but that's all the difference there is.

  • Using an Array in a JSP page

    I am currently storing values from a database into an array
    im my servlet. I have a JSP page and I'm trying to set
    the datafields on this page to the values held in the array.
    I need to send the array from the servlet to the JSP page
    and then figure out how I retrieve it at the other end.
    Can anyone help????????

    Here's the code I'm using for my Sevlet:
    package SASSSpkg;
    import java.io.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    import java.util.*;
    import java.sql.*;
    import javax.swing.*;
    public class UserLogin extends HttpServlet{
         private Connection connection;
    private ResultSet resultSet;
         private Statement statement;
         public String getusername, getpassword, getdatabase;
         private String customerId;     
         private String title;
         private String firstName;
         private String secondName;
         private String surname;
         private String residentialAddress;
         private String dateOfBirth;
         private String correspondenceName;
         private String maritalStatus;
         private String gender;
         private String securityId;
         private String postCode;
         private String dateOfFirstContact;
         private String homeTel;
         private String businessTel;
         private String currentAddressEntryDate;
         private String nationalInsuranceNumber;
         private String dateLastUpdated;
         public ArrayList values = new ArrayList();
         public void init(ServletConfig config) throws ServletException
              super.init(config);
         public UserLogin()
         public void ConnectToDatabase() throws Exception
    String url = "jdbc:odbc:SASSS";
    String username = getusername;
    String password = getpassword;
    // Load the driver to allow connection to the database
    try {
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    connection = DriverManager.getConnection( url, username,
    password);
    catch (ClassNotFoundException cnfex)
    throw new Exception("cannot connect to database");
    catch (SQLException sqlex)
    throw new Exception("cannot connect to database");
    public void getResultSetData()
    try
    String query = "SELECT DISTINCT CUSTOMER_ID, TITLE, FORENAME1, FORENAME2, SURNAME, DATE_OF_BIRTH, CUSTOMER_SALUTATN, MARITAL_STATUS, GENDER, SECURITY_NAME, FIRST_CONTACT_DATE,POSTCODE, TELEX, DATE_AT_ADDRESS, NATIONAL_INS_NUM, ADDRESS.LAST_UPDATED, ADDRESS.TELEPHONE FROM CUSTOMER, ADDRESS, CUSTOMER_ADDRESS WHERE CUSTOMER.CUSTOMER_CODE = CUSTOMER_ADDRESS.CUSTOMER_CODE AND CUSTOMER_ADDRESS.ADDRESS_ID = ADDRESS.ADDRESS_ID";
    statement = connection.createStatement
    (ResultSet.TYPE_SCROLL_INSENSITIVE,
    ResultSet.CONCUR_UPDATABLE);                
    resultSet = statement.executeQuery(query);
    resultSet.first();
         for (int i = 0; i <= 16; i ++)
              values.add(resultSet.getString(i + 1));
              statement.close();          
    catch(SQLException sqlex)
    sqlex.printStackTrace();
         public void doPost(HttpServletRequest req, HttpServletResponse
    res)
              throws ServletException, IOException
         try{
                   boolean dbConnection;
                   // Get username and password from fields on web
    page
                   getusername = req.getParameter("UserName");
                   getpassword = req.getParameter("Password");
                   getdatabase = req.getParameter("Database");
                   PrintWriter output = res.getWriter();
                   res.setContentType("text/html");
                   if(getusername.equals("") || getpassword.equals
                   res.sendRedirect
    ("http://localhost:9080/SASSS/ErrorPage.jsp");
                   return;
                   else
                        ConnectToDatabase();
                        getResultSetData();
                        res.sendRedirect
    ("http://localhost:9080/SASSS/EmployeeDetails.jsp");
              catch(Exception ex) {
                   res.sendRedirect
    ("http://localhost:9080/SASSS/ErrorPage.jsp");          
         public void doGet(HttpServletRequest req, HttpServletResponse
    resp)
              throws ServletException, IOException
              req.setAttribute("myArrayList", values);
         public String getCustomerId()
              return customerId;
         public void setCustomerId(String Id)
              customerId = Id;
         public String getTitle()
              return title;
         public void setTitle(String theTitle)
              title = theTitle;;
         public String getFirstName()
              return firstName;
         public void setFirstName(String theFirstName)
              firstName = theFirstName;
         public String getSecondName()
              return secondName;
         public void setSecondName(String theSecondName)
              secondName = theSecondName;
         public String getSurname()
              return surname;
         public void setSurname(String theSurname)
              surname = theSurname;
         public String getResidentialAddress()
              return residentialAddress;
         public void setResidentialAddress(String theResidentialAddress)
              residentialAddress = theResidentialAddress;
         public String getDob()
              return dateOfBirth;
         public void setDob(String theDOB)
              dateOfBirth = theDOB;
         public String getCorrespondenceName()
              return correspondenceName;
         public void setCorrespondenceName(String theCorrespondenceName)
              correspondenceName = theCorrespondenceName;
         public String getMaritalStatus()
              return maritalStatus;
         public void setMaritalStatus(String theMaritalStatus)
              maritalStatus = theMaritalStatus;
         public String getGender()
              return gender;
         public void setGender(String theGender)
              gender = theGender;
         public String getSecurityId()
              return securityId;
         public void setSecurityId(String theSecurityId)
              securityId = theSecurityId;
         public String getPostCode()
              return postCode;
         public void setPostCode(String thePostCode)
              postCode = thePostCode;
         public String getDateOfFirstContact()
              return dateOfFirstContact;
         public void setDateOfFirstContact(String theDateOfFirstContact)
              dateOfFirstContact = theDateOfFirstContact;
         public String getHomeTel()
              return homeTel;
         public void setHomeTel(String theHomeTel)
              homeTel = theHomeTel;
         public String getBusinessTel()
              return businessTel;
         public void setBusinessTel(String theBusinessTel)
              businessTel = theBusinessTel;
         public String getCurrentAddressEntryDate()
              return currentAddressEntryDate;
         public void setCurrentAddressEntryDate(String
    theCurrentAddressEntryDate)
              currentAddressEntryDate = theCurrentAddressEntryDate;
         public String getNationalInsuranceNumber()
              return nationalInsuranceNumber;
         public void setNationalInsuranceNumber(String
    theNationalInsuranceNumber)
              nationalInsuranceNumber = theNationalInsuranceNumber;
         public String getDateLastUpdated()
              return dateLastUpdated;
         public void setDateLastUpdated(String theDateLastUpdated)
              dateLastUpdated = theDateLastUpdated;
    Here's the code I'm using for my JSP:
    <HEAD><SCRIPT type="text/javascript">
    <!--
    var _sstmrID = null;
    var _sstmrON = false;
    var _sspos   = 80;
    function _ScrollStatus(msg, delay)
    if (_sstmrON)
    window.clearTimeout(_sstmrID);
    _sstmrON = false;
    var statmsg = "";
    if (_sspos >= 0)
    for (s = 0; s < _sspos; s++)
    statmsg += " ";
    statmsg += msg;
    else
    statmsg = msg.substring(-_sspos, msg.length);
    window.status = statmsg;
    sspos = (-sspos > msg.length) ? 80 : _sspos - 1;
    fname = "_ScrollStatus('" + msg + "', " + delay + ")";
    _sstmrID = window.setTimeout(fname, delay);
    _sstmrON = true;
    //-->
    </SCRIPT><SCRIPT type="text/javascript">
    <!--
    function _ShowObj(lId)
    var ob;ob=new Array;
    var appVer=parseInt(navigator.appVersion);
    var isNC=false,isN6=false,isIE=false;
    if (document.all && appVer >= 4) isIE=true; else
    if (document.getElementById && appVer > 4) isN6=true; else
    if (document.layers && appVer >= 4) isNC=true;
    if (isNC)
    w_str = "document." + lId;ob[lId] = eval(w_str);
    if (!ob[lId]) ob[lId] = _FindHiddenObj(document, lId);
    if (ob[lId]) ob[lId].visibility = "show";
    if (isN6)
    ob[lId] = document.getElementById(lId);
    ob[lId].style.visibility = "visible";
    if (isIE)
    w_str = "document.all.item(\"" + lId + "\").style";ob[lId] = eval(w_str);
    ob[lId].visibility = "visible";
    function _FindHiddenObj(doc, lId)
    for (var i=0; i < doc.layers.length; i++)
    var w_str = "doc.layers.document." + lId;
    var obj;obj=new Array;
    obj[lId] = eval(w_str);
    if (!obj[lId]) obj[lId] = _FindHiddenObj(doc.layers[i], lId);
    if (obj[lId]) return obj[lId];
    return null;
    //-->
    </SCRIPT></HEAD>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
    <%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
    <html:html>
    <HEAD>
    <%@ page
    language="java"
    contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"
    errorPage="ErrorPage.jsp"
    %>
    <META http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    <META name="GENERATOR" content="IBM WebSphere Studio">
    <META http-equiv="Content-Style-Type" content="text/css">
    <LINK href="style.css" rel="stylesheet" type="text/css">
    <h2>
    <%@page import="SASSSpkg.UserLogin"%>
    <%@page import="java.util.*"%>
    <%@page import="javax.servlet.*"%>
    <%@page import="javax.servlet.http.*"%>
    <% UserLogin ul = new UserLogin(); %>
    <TITLE>SASSS Employee Details</TITLE>
    </HEAD>
    <BODY bgcolor="#c0c0c0"><FORM action="servlet/SASSSpkg.UserLogin" method="get">
    <%
    if (request.getAttribute("myArrayList") != null) {
    ArrayList Alist = (ArrayList)request.getAttribute("myArrayList");
    ul.setCustomerId(Alist.get(0).toString());
    else {
    response.sendRedirect("http://localhost:9080/SASSS/ErrorPage.jsp");
    %>
    <TABLE border="0" width="792" height="359">
         <TBODY>
              <TR>
                   <TD colspan="6" valign="middle" align="center" height="58"><B>Customer
                   Id</B> <INPUT type="text" name="customerId" size="20" maxlength="10"
                        disabled value='<%= ul.getCustomerId() %>'></TD>
              </TR>
              <TR>
                   <TD align="center" height="57" width="160"><SPAN
                        style="font-weight: bold"><B>Title</B><BR>
                   <SELECT name="title" size="1">
                             <OPTION><%= ul.getTitle()%></OPTION>
                             <OPTION>Mr</OPTION>
                             <OPTION>Mrs</OPTION>
                             <OPTION>Miss</OPTION>          
                   </SELECT></SPAN></TD>
                   <TD align="left" height="57" width="171"><SPAN
                        style="font-weight: bold"><B><STRONG>First Name</STRONG></B><BR>
                   <SCRIPT type="text/javascript">
    <!--
    _ScrollStatus("How cool is this", 2);
    //-->
    </SCRIPT><INPUT type="text" name="firstName" size="20" maxlength="25" value = '<%= ul.getFirstName() %>' ></SPAN></TD>
                   <TD align="left" height="57" colspan="2"><SPAN
                        style="font-weight: bold"><B>Second Name</B><BR>
                   <INPUT type="text" name="secondName" size="20" maxlength="25" value='<%= ul.getSecondName() %>'></SPAN></TD>
                   <TD align="left" height="57" colspan="2"><SPAN
                        style="font-weight: bold">Surname<BR>
                   <INPUT type="text" name="surname" size="20" maxlength="25" value='<%= ul.getSurname() %>'> </SPAN></TD>
              </TR>
              <TR>
                   <TD colspan="2" align="center" rowspan="3"><B>Residential Address</B><BR>
                   <TEXTAREA rows="7" cols="31" name="residentialAddress" ><%= ul.getResidentialAddress() %></TEXTAREA></TD>
                   <TD align="left" height="66" colspan="2"><B>Date of Birth</B><BR>
                   <INPUT type="text" name="dateOfBirth" size="20" maxlength="10" value='<%= ul.getDob() %>'></TD>
                   <TD align="left" colspan="2"><B>Correspondence Name<BR>
                   <INPUT type="text" name="correspondenceName" size="20" maxlength="25" value='<%= ul.getCorrespondenceName() %>'>
                   </B></TD>
              </TR>
              <TR>
                   <TD align="left" height="42" colspan="2"><B>Marital Status </B> <SELECT
                        name="maritalStatus" style="">
                        <OPTION selected><%= ul.getMaritalStatus()%></OPTION>
                        <OPTION>Divorced</OPTION>
                        <OPTION>Married</OPTION>
                        <OPTION>Seperated</OPTION>
                        <OPTION>Single</OPTION>
                        <OPTION>Widowed</OPTION>
                   </SELECT></TD>
                   <TD align="left" colspan="2"><B>Gender</B> <SELECT name="gender">
                        <OPTION><%= ul.getGender()%></OPTION>
                        <OPTION>Female</OPTION>
                        <OPTION>Male</OPTION>
                   </SELECT></TD>
              </TR>
              <TR>
                   <TD colspan="4" height="56"><B>Security
                   Id     </B><INPUT type="text" name="securityId"
                        size="20" maxlength="20" value='<%= ul.getSecurityId() %>'></TD>
              </TR>
              <TR>
                   <TD height="55" align="left" colspan="2" nowrap><B>
                      Post Code   </B> <INPUT type="text"
                        size="15" maxlength="8" value='<%= ul.getPostCode() %>' name="postCode"></TD>
                   <TD height="55" align="left" colspan="2"><B>Date of First Contact</B><BR>
                   <INPUT type="text" name="dateOfFirstContact" size="10" maxlength="10" value='<%= ul.getDateOfFirstContact() %>'>
                   </TD>
                   <TD height="55" rowspan="5" align="center" colspan="2"><SELECT
                        size="9" name="aditionalDetailForms">
                        <OPTION value="">Products Held</OPTION>
                        <OPTION>Employment</OPTION>
                        <OPTION>Dependants</OPTION>
                        <OPTION>Residential Details</OPTION>
                        <OPTION>Assets/Liabilities</OPTION>
                        <OPTION>Income/Commitments</OPTION>
                        <OPTION>Banks/Building Societies</OPTION>
                        <OPTION>Credit Cards</OPTION>
                        <OPTION>Leads and Follow ups</OPTION>
                        <OPTION value=""></OPTION>
                   </SELECT></TD>
              </TR>
              <TR>
                   <TD height="41" align="left" colspan="2" nowrap><B>   Home
                   Tel                         </B>
                   <INPUT type="text" name="homeTel" size="18" maxlength="14" value='<%= ul.getHomeTel() %>'></TD>
                   <TD height="41" align="left" colspan="2"><INPUT type="button"
                        name="lastAddress" value="Last Address"></TD>
              </TR>
              <TR>
                   <TD height="49" align="left" colspan="2" nowrap><B>   Business
                   Tel                  </B>
                   <INPUT type="text" name="businessTel" size="18" maxlength="14" value='<%= ul.getBusinessTel() %>'></TD>
                   <TD height="49" align="left" valign="bottom" colspan="2"><B>N.I.
                   Number</B></TD>
              </TR>
              <TR>
                   <TD height="42" colspan="2" nowrap><B>   Current
                   Address Entry Date  </B> <INPUT
                        type="text" name="currentAddressEntryDate" size="10" maxlength="10" value='<%= ul.getCurrentAddressEntryDate() %>'></TD>
                   <TD height="42" colspan="2"><INPUT type="text"
                        name="nationalInsuranceNumber" size="20" maxlength="9" value='<%= ul.getNationalInsuranceNumber() %>'></TD>
              </TR>
              <TR>
                   <TD height="44" colspan="2" nowrap><B>   Date Last
                   Updated                   </B>
                   <INPUT type="text" name="dateLastUpdated" size="10" maxlength="15" value='<%= ul.getDateLastUpdated() %>'></TD>
                   <TD height="44" align="left" colspan="2"><INPUT type="button"
                        name="directMailExclusions" value="Mail Exclu">    <INPUT
                        type="button" name="telephoneExclusions" value="Tel Exclu"></TD>
              </TR>
              <TR>
                   <TD height="44" align="left" colspan="6" nowrap>        <INPUT
                        type="submit" name="ok" value=" OK ">            <INPUT
                        type="button" name="forward" value=" >> ">            <INPUT
                        type="button" name="exit" value=" Exit ">            <INPUT
                        type="button" name="delete" value=" Delete ">            <INPUT
                        type="reset" name="refresh" value=" Refresh ">            <INPUT
                        type="button" name="help" value=" Help "></TD></TR>
    </TABLE></FORM>
    </BODY>
    </html:html>
    The problem is, I'm trying to store String values into an array,
    or a result set and then store them in the data fields on my jsp page.
    When I use my set method such as setCustomerId(values.get(0));
    it sets the variable customerId to the value I want but when I try to
    call the get method in the JSP page to assign it to the data field it
    will not retrieve it.
    Can anyone solve this, I've been at it for days now????

  • How to Include a servlet in a jsp

    Hello,
    My jsp pages are all tied to respective Servlets. So when I have to forward to a jsp, I forward to a servelt which redirects to that jsp.
    Now I have a jsp page which has to include another jsp page.
    So I am trying to include a servlet in my jsp page which inturn redirects itself to the included jsp.
    Have tried doing the following
    <jsp:include page="../../servlet/ServletName" flush="true">
    </jsp:include>
    does not work. It compiles well but no output
    any ideas ????
    ~ Soumya

    It does not seem to work... Let me give you the snippet of code I used.
    calendarEntry.java - the parent jsp
    <tr rowspan="60%">
    <td width="100%">
         <jsp:include page="file://c:/../../servlet/MonthEventList">
         </jsp:include>
    </td>
    </tr>
    MonthEventList.java - the included servlet
    import javax.servlet.*;
    import javax.servlet.http.*;
    public class MonthEventList extends HttpServlet {
         * Attributes
         private static final String CONTENT_TYPE = "text/html";
         private HttpSession session;
         public void init() throws ServletException
         public void doPost(HttpServletRequest request,
    HttpServletResponse response) throws
    ServletException, IOException
              try {     
              HttpSession session = request.getSession(true);
              String url;
         url = "/jsp/site/calendar/monthEventList.jsp";
                        //ReDirect to where the page is going
                        response.sendRedirect(url);
                        return;
              } catch (Exception ex) {
              String url="/jsp/site/calendar/main/servletError.jsp;
         response.sendRedirect(url);
              return;
         public void doGet(HttpServletRequest request,HttpServletResponse
    response) throws ServletException, IOException
              doPost(request, response);
    monthEventList.jsp
    just displays some dummy data
    So if this is the case, do you think the <jsp:include> can work ??
    Thanks in advance
    Soumya

  • How to display outsream from a servlet in a JSP

    I wrote a jsp file to call a Servlet, then want to display the result from the servlet in another jsp file. Anyone can give me possible solution or an example to illustrate it.
    Many thanks in advance.
    the file that call servlet in a jsp is as follow
    <form method="POST" action="myservlet">
    <table>
    <tr>
    <th align="center" colspan="2">
    Enter The query words
    </th>
    </tr>
    <tr>
    <th align="right">query words:</th>
    <td align="left">
    <input type="text" name="querywords" size="60">
    </td>
    </tr>
    <tr>
    <td align="right">
    <input type="submit" value="Search">
    </td>
    <td align="left">
    <input type="reset" value="Reset">
    </td>
    </tr>
    </table>
    </form>
    ............

    I would suggest that you use the Servlet to retrieve the data you are after and store it in the session. Then forward the user onto the JSP page where it can retrieve the object from the session and present it to the user in a formatted view.

  • Calling servlets from a jsp in a directory

    Hello,
    I use JBuilder 9 to develop a web application, and I organize all jsp files in directories inside root directory. The problem is that when I try to use any servlet in the project, I have to use the following address "http://localhost8080/servletName" and it worked fine, but when I run the application on another machine that has port 8083 for JBuilder it didn't work of course. So is there a generic address that I can use that can work with any port?
    Sorry for the long message,
    Thanks,

    yes, but when I use the relative name of the servlet, I get an error saying that the servlet is not found inside the directory in which the jsp(the one from which I call the servlet) exists. For some reason the program searches for the servlet in the same directory and of course doesn't find it. What do you think I can do about this?
    Thanks,

  • How can I use java swing class in JSP page design

    I am a new developer in Java server pages. I want to use layout managers available in java swing classes to design the page. Can any body suggest me a way to do this.Is it possible if I do it with servelets.

    So, you want to use layout managers within your JSPs?
    The immediate answer is that "it isn't a good idea". The more considered answer is "tell us what you're up to".
    Are you coding all presentation within a traditional JSP? That is, HTML, customer or library tags and/java scriptlets?
    Or are you building your HTML within your servlets and sending that back to the browser?
    If the first, then you are probably better off either using explicit HTML tables (or the equivalent custom tags) or finding a library that you can use.
    If the second, you can write classes similar to the Swing layout managers that end up being a fancy way of putting elements into an HTML table. We have exactly that in my current environment. I wouldn't recommend rolling your own and I'd tend to leave all that presentation stuff to the JSP.
    In any case, you can't really use the Swing layout managers as they are for an entirely different pradigm.

  • How do I Display a string from a servlet into a JSP Page???? NEED HELP!!!!

    Hi guys,
    How do I Display a string from a servlet into a JSP Page...
    Ive tried so many bloody things!.....
    Simply.
    I get text from JSP. The servlet does what ever it does to the string.
    Now. Ive create sessions and bean things,.... how the hell do I display it in a text box... I can display on the screen.. but not in the text box.!!!
    please help!!!

    hmmm, I dont really like using JSP programming, u should be using JAVA..
    the way to do it is:
    Call and cast to the bean like this:
    <%@ page import="beans.*" %>
    <% //cast to bean get request create object
    userNameBean u= (userNameBean) request.getSession().getAttribute("userNameBean");
    then... all you do is call it like this:
    <input type="text" name="firstName" value="<%= u != null? u.getFirstName(): "" %>">
    this is the real programmers way,,,
    chet.~

Maybe you are looking for

  • Replaced hard drive, cant get back to os x 10.8

    I installed 10.4 to get computer running and now I cant update my system to where i was before the crash os x 10.8. where do i start?

  • How do u un disable a iphone i locked it completely and it says now to connect to itunes ***

    how do u undisable a iphone it says to connect to itunes because i forgot my password and i cant figure out what to go to on itunes please help help help #***

  • Lines in dialog boxes only

    I just upgraded to a mac pro with an ATI 2600 video card. I get two horizontal lines in dialog boxes.Never had this with my old G4. All other windows and desktops are fine. Anyone know how to fix this?

  • Directly change in production environment.....

    Hi Experts,      Hope you are well.      Could you please share that which changes can we make directly in production environment at the configuration level, without create transport request.      Please share with me the changes list in production e

  • Have to reset synching each time

    I have my ipod set to synch all playlists and songs. From time to time I plug it into other computers to get podcasts only. When I plug back into my main mac, I have to reset the synch all songs and playlists. In the interim, some songs are no longer