Displaying calculated data in JSP pages

This is a general question about displaying data in JSP pages which has been calculated through ViewObj Routines. I have exposed the methods to the application level however, I want these methods to automatically run on the launch of the page. I can so this with a data action in the struts file. However, I have lots of these methods (all bringing single values of data), it seems inelegant to have 10 data actions or so. What's the best way to expose and show data on a JSP page automatically which has been calculated from the database rows.
Thanks in advance

You could convert the vo row to a hash using BeanUtils and then you could do what you want with it programmaticaly to automatically dissplay the lhash values.

Similar Messages

  • How to Hightlight the Data in Jsp Page

    How to Hightlight the Data in Jsp Page,
    I am doing doing search page,based on values given search page those are sent to servlet,in servlet based on some conditions if particuler id i am getting then i am redirecting to Respective jsp page with highlight the data from database..
    Thanks in advance...

    "Highlighting data in JSP sounds strange".
    Without looking at your search specific algorithms I feel you are finally going to display a page (HTML content) to user which contains highlighted text. Highlighting is not directly related to server side language you use (JSP, ASP, PHP etc.). This is purely HTML and CSS. However, server side script (such as JSP) should generate HTML content for getting highlight effect.
    Following HTML shows highlighted text using background-color property on span element.
    <html>
      <head>
        <title></title>
        <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
      </head>
      <body>
          <p style="font-size:1.1em">This is a long paragraph which contains <span style="background-color: yellow;">highlighted text</span> and non highlighted text.</p>
      </body>
    </html>Thanks,
    Mrityunjoy
    Edited by: mrityunjoy on 14 Jun, 2010 3:30 AM

  • How to display uploaded image in jsp page.

    Hello,
    I am using struts 1.2.9 and and have uploaded image on the server. Now what I want to do display the image in jsp page after clicking on one link in jsp. I have tried many thing to display image in jsp page. But I am getting an error during displaying image in jsp. I have displayed absolute path in servlet. and used InputStream and outputstream to display image in jsp page.
    Can any one help.
    Thanks in advance
    Manveer Singh

    Follow this. This topic is very popular recently on the forum.

  • How to display all data on one page in web app

    Hello.
    So I have web app JSF (IceFaces framework) + JBoss all Crystal Report working perfectly. So I have page with Crystal Report tags (e.g.
    <bocrv:reportPageViewer reportSource="#{crystalReport.reportPath}" ...
    in this report I have table with some data (data from DB) and I want to display this data on one page. Unfortunately now this data are moving to the next page and unfortunately I even donu2019t know how switch to the next page (I see only info e.g. 1with 2).
    So how to display this data on one page if its impossible how to torn on pagination.

    So I canu2019t do this, I canu2019t display all data on one page (until Iu2019m using JSF tags)?
    In JSF tags Iu2019m setting only path to file. In my bean Iu2019m using u201CReportClientDocumentu201D object itu2019s easy way to load report file (u201Copenu201D method) and set parameters (u201CgetDataDefController().getParameterFieldController()u201D method) and also connect to data base (u201Clogonu201D method) but I havenu2019t this property u201CsetSeparatePages(boolean)u201D.
    Maybe Iu2019m doing this wrong and there is a simpler way maybe I can use somehow u201CCrystalReportVieweru201D please give my any advice.

  • Sensors in BPEL to publish data to JSP page ??

    Hi Guys
    In the BPEL console the result comes in a XML format. I want the result to be displayed on a JSP page that i created. So that the end user is comfortable to see results. I wanted to know can sensors be used to capture the results from the BPEL console and publish it on the JSP page. If we can do it, which kind of sensors will work. If you could provide me some examples on how i can do it .. It will be really helping . I am new to BPEL and need to complete it urgently. heLp required
    regards

    Hi Marc / Anirudh
    Thanks a lot for providing information. But the clients want the results to be displayed on a Different JSP page. I have created that page. Now I am looking to pass the Payload (The results of the BPEL process) to this JSP page so that i can display over there. I have googled it but didnt find anything. Then i came to know that something like sensors can do it. I have no clue about it. Kindly help
    regards

  • JSP and servlets(displaying Data On JSP page)

    Hiii all
    i am new to JSP ...also to servets
    tell me hw to print my data on the JSP page,
    i can print my data on the server,that data i want to print on JSP page
    if u all have e.g's it will be very good
    Thanks in advance
    Take Care
    Rahul :)

    What do you mean "print data on a JSP?" If you simply mean display dynamic content, you should def read up both on sun's resources and other googled resources for JSP walkthroughs...

  • No data in JSP Page

    Hi,
    JDeveloper: 10.1.3.3.0.4157
    Database: Oracle XE 10.2.0.1.0
    Browser: Firefox 2.0.0.14
    I am doing the following steps but the resulting web page displays no data. Any
    help would be appreciated:
    - This is all in JDeveloper...
    - Create an application, 'testapp', using the template [JSP, Struts, ADF BC].
    - On the Model node, create a Business Components Diagram. Rename this to
    'Business Domain Diagram' and put it in the 'testapp.model.businessdomain'
    package.
    - Go to a databse connection, expand Tables and drag a table,
    'SYSTEM_PARAMETERS' on to the diagram. The table has 2 VARCAHR2(100) columns,
    one of which is the primary key. I choose 'Business Component Entity Objects'
    from the 'Create From Database Object' popup.
    - I then right-click on the diagram and select 'Generate/Default Data Model
    Components for Diagram'.
    - I put the objects in the package 'testapp.model.datamodel' and create a new
    application module; 'TestModule'.
    - On the testapp.model.datamodel node, I create another Business Components
    Diagram; 'Data Model Diagram' and, from the same node, drag
    SystemParametersView and TestModule on to this new diagram.
    - I then right-click TestModule and select 'Test', and the Business Components
    Browser pops up allowing me to navigate through the dozen or so rows in the
    table.
    Right now I know that the database connection is all good and my java objects
    can see then.
    - I right-click on the ViewController node and select 'Open Struts Page Flow'.
    From the Components pallet, I drag a 'Data Page' icon on to the
    struts-config.xml diagram and rename it 'TestPage'.
    - I then double-click this icon and accept all the default settings to create
    the page and open it in the page diagrammer.
    - From the 'Data Connection' pallet, I expand TestModuleDataControl' and drag
    SystemParametersView1 on to the page.
    - From the drag options, I choose 'Forms/Read-Only Form' and a form
    containing a table is created. The table is 2x2 and contains bindings for
    the databae table column names and data.
    Now the naughty bit...
    - I click the 'Run' icon, a new tab opens up on Firefox and the page renders -
    i.e. I get a 2x2 HTML Table - but there is no data in it. I can see neither
    the column name labels or the contents of the row. There being no text in
    the table, it has collapsed to 2 very thin rows. I think that I should see
    data from one of the rows in the table and I appreciate that I can't see
    any others because I have not yet added any navigation.
    I would appreciate it if anyone could point at the fatal flaw in this
    procedure.
    Not sure if this helps but below is the log from the embedded OC4J server:
    [Starting OC4J using the following ports: HTTP=8988, RMI=23891, JMS=9227.]
    C:\jdev\jdev\system\oracle.j2ee.10.1.3.41.57\embedded-oc4j\config>
    C:\jdev\jdk\bin\javaw.exe -client -classpath C:\jdev\j2ee\home\oc4j.jar;C:\jdev\jdev\lib\jdev-oc4j-embedded.jar -Xverify:none -XX:MaxPermSize=256m -DcheckForUpdates=adminClientOnly -Doracle.application.environment=development -Doracle.j2ee.dont.use.memory.archive=true -Doracle.j2ee.http.socket.timeout=500 -Doc4j.jms.usePersistenceLockFiles=false oracle.oc4j.loader.boot.BootStrap -config C:\jdev\jdev\system\oracle.j2ee.10.1.3.41.57\embedded-oc4j\config\server.xml
    [waiting for the server to complete its initialization...]
    04-May-2008 09:45:07 com.evermind.server.jms.JMSMessages log
    INFO: JMSServer[]: OC4J JMS server recovering transactions (commit 0) (rollback 0) (prepared 0).
    04-May-2008 09:45:07 com.evermind.server.jms.JMSMessages log
    INFO: JMSServer[]: OC4J JMS server recovering local transactions Queue[jms/Oc4jJmsExceptionQueue].
    Ready message received from Oc4jNotifier.
    Embedded OC4J startup time: 95640 ms.
    08/05/04 09:46:02 Oracle Containers for J2EE 10g (10.1.3.3.0) initialized
    Target URL -- http://10.1.1.2:8988/testapp-ViewController-context-root/TestPage.jsp
    04-May-2008 09:46:55 org.apache.struts.util.PropertyMessageResources <init>
    INFO: Initializing, config='org.apache.struts.util.LocalStrings', returnNull=true
    04-May-2008 09:46:55 org.apache.struts.util.PropertyMessageResources <init>
    INFO: Initializing, config='org.apache.struts.action.ActionResources', returnNull=true
    04-May-2008 09:46:56 org.apache.struts.util.PropertyMessageResources <init>
    INFO: Initializing, config='testapp.view.ApplicationResources', returnNull=true
    04-May-2008 09:46:57 oracle.adf.share.config.ADFConfigFactory findOrCreateADFConfig
    INFO: oracle.adf.share.config.ADFConfigFactory No META-INF/adf-config.xml found
    04-May-2008 09:47:01 org.apache.struts.util.PropertyMessageResources <init>
    INFO: Initializing, config='org.apache.struts.taglib.html.LocalStrings', returnNull=true
    04-May-2008 09:47:01 org.apache.struts.util.PropertyMessageResources <init>
    INFO: Initializing, config='org.apache.struts.taglib.html.LocalStrings', returnNull=true
    04-May-2008 09:47:01 org.apache.struts.util.PropertyMessageResources <init>
    INFO: Initializing, config='org.apache.struts.util.LocalStrings', returnNull=true
    04-May-2008 09:47:01 org.apache.struts.util.PropertyMessageResources <init>
    INFO: Initializing, config='org.apache.struts.taglib.html.LocalStrings', returnNull=true
    04-May-2008 09:47:01 org.apache.struts.util.PropertyMessageResources <init>
    INFO: Initializing, config='org.apache.struts.taglib.html.LocalStrings', returnNull=true
    Thanks in advance.
    Steve

    Hi,
    make sure the Struts action in the Struts diagrammer is selected when pressing the run button. Or select the action and choose run from the context menu
    Frank

  • How to retrieve records from a database and display it in a jsp page.Help!!

    Hello everyone ! im very new to this forum.Please help me to solve my problem
    First i ll explain what is my requirement or needed.
    Actually in my web page i have text box to enter start date and end date
    and one list box to select the month .If user select or enter the dates in text box
    accordingly the data from ms access database has to display in a jsp page.
    Im using jsp and beans.
    I tried returning ResultSet from bean but i get nothing display in my web page
    instead it goes to error page (ErrorPage.jsp) which i handle in the jsp.
    I tried many things but nothing work out please help me to attain a perfect
    solution. I tried with my bean individually to check whether the result set has
    values but i got NullPointerException . But the values which i passed or
    available in the database.
    I dint get any reply for my last post please reply atleast to this.
    i get the date in the jsp page is by this way
    int Year=Integer.parseInt(request.getParameter("year"));
    int Month=Integer.parseInt(request.getParameter("month"));
    int Day=Integer.parseInt(request.getParameter("day"));
    String startdate=Day+"/"+Month+"/"+Year;
    int Year1=Integer.parseInt(request.getParameter("year1"));
    int Month1=Integer.parseInt(request.getParameter("month1"));
    int Day1=Integer.parseInt(request.getParameter("day1"));
    String enddate=Day1+"/"+Month1+"/"+Year1;But this to check my bean whether it return any result!
    public void databaseConnection(String MTName,String startDate,String endDate)
    try
             java.text.SimpleDateFormat dateFormat=new java.text.SimpleDateFormat("dd/MM/yyyy");
             java.util.Date fromDate=dateFormat.parse(startDate);
            java.util.Date tillDate=dateFormat.parse(endDate);          
            java.sql.Date sqlFromDate=new java.sql.Date(fromDate.getTime());
            java.sql.Date sqlTillDate=new java.sql.Date(tillDate.getTime());
              String query1="select MTName,Date,MTLineCount from Main where MTName='"+MTName+"'  and Date between '"+sqlFromDate+"' and '"+sqlTillDate+"' " ;
            System.out.println(query1);
              Class.forName(driver);
             DriverManager.getConnection(url);
             preparedStatement=connection.prepareStatement(query1);
             preparedStatement.setString(1,"MTName");
              preparedStatement.setDate(2,sqlFromDate);
              preparedStatement.setDate(3,sqlTillDate);
              resultSet=preparedStatement.executeQuery();           
               while(resultSet.next())
                        System.out.println(resultSet.getString(1));
                        System.out.println(resultSet.getDate(2));
                        System.out.println(resultSet.getInt(3));
            catch (Exception e)
             e.printStackTrace();
    I Passed value from my main method is like thisl
    databaseConnection("prasu","1/12/2005","31/12/2005");Please provide solutions or provide some sample codes!
    Help!
    Thanks in advance for replies

    Thanks for ur reply Mr.Rajasekhar
    I tried as u said,
    i tried without converting to sql date ,but still i din't get any results
    java.text.SimpleDateFormat dateFormat=new java.text.SimpleDateFormat("dd/MM/yyyy");
             java.util.Date fromDate=dateFormat.parse(startDate);
            java.util.Date tillDate=dateFormat.parse(endDate);          
              String query1="select MTName,Date,MTLineCount from linecountdetails where mtname='"+MTName+"'  and Date >='"+fromDate+"' and Date <='"+tillDate+"' " ;
            System.out.println(query1);
    //From main method
    databaseConnection("prasu","1/12/2005","31/12/2005");I got the output as
    ---------- java ----------
    select MTName,Date,MTLineCount from linecountdetails where mtname='prasu'  and Date >='Thu Dec 01 00:00:00 GMT+05:30 2005' and Date <='Sat Dec 31 00:00:00 GMT+05:30 2005'
    java.lang.NullPointerException
    null
    null
    java.lang.NullPointerException
    Output completed (4 sec consumed) - Normal TerminationThanks
    Prasanna.B

  • Display current date in jsp?

    I hate asking for code, but I can't find anything on this. I'm trying to display the current date in the format YYYYMMDD on a jsp page without using scriplets. I've seen getting the time in milliseconds used through
    <jsp:useBean id="now" class="java.util.GregorianCalendar" />
    <c:out value="${now.timeInMillis}" />but now.year/Year/YEAR etc all give me 500 errors. I've also tried
    <jsp:useBean id="now" class="java.util.Date" />
    <c:out value="${now.year}" />But this just yields a constant. I know there is the SimpleDateFormat which I think would go with the java.util.Date example, but I'm not sure how it would be used in this context. Can anyone help me to get the date?

    Or how about using the JSTL tag for it:
    <jsp:useBean id="now" class="java.util.Date" />
    <fmt:formatDate value="${now}"/>This tag leverages the java.text.SimpleDateFormat to do its job.
    Cheers,
    evnafets

  • Display processing data ... page when gettting data

    I need to display a page which will display processing data please wait .... till i get the data from the database. How do i implement this in jsp ??

    Instead of going directly to JSP/servlet performing time consuming task, go to an intermediate JSP that has this code...
    <%
         String timeConsumingTask = "absolute URL to actual time consuming task";
    %>
    <META http-equiv="refresh" CONTENT="0; URL=<%= timeConsumingTask %>">
    <br>please wait ....

  • Implementing Database codes FAIL /error in parsing data into jsp page

    Hi there,
    I have this problem trying to build a portal application. I am using the JSPDynPage, jsp page and a bean to build a page.
    I have this problem parsing data from JSPDynPage to the beans and to the jsp page.
    I tested out the connection between the beans and the jsp page. There is no error parsing information from the beans to the jsp page.
    So i tried to test out the codes for the database from the beans.
    Will this work? Because it does not display the results i want.
    I need an Solution asap to find out wad is wrong also also the correct codes to the database.
    public String db(){
    try {
                 InitialContext iC = new InitialContext();
                 DataSource dataSource = (DataSource)iC.lookup("java:env/jdbc/mySQL");
                 java.sql.Connection connection = dataSource.getConnection();
                 PreparedStatement st = connection.prepareStatement("SELECT name FROM test WHERE id='123'");
                 ResultSet resultSet = st.executeQuery();
                 while (resultSet.next()){
                      name = resultSet.getString("name");
                      name = name.toString();
                 connection.close();
                 return name;
                 } catch(Exception n){
                      e = "Exception";
                      return e;
    This is the method i put in the beans to test out the database connection.
    Thanks Loads
    Quatre

    Hi there,
    Thanks for the reply, i thought that no one is going to reply me anymore. Thanks loads.
    Bean Class name: Bean1
    Bean Packeage name: Beans1
    Bean id : myBean1
    Jsp Codes
    <%@ taglib uri="tagLib" prefix="hbj" %>
    <jsp:useBean id="myBean1" scope="application" class="Beans1.Bean1" />
    <hbj:content id="myContext" >
      <hbj:page title="PageTitle">
       <hbj:form id="myFormId" >
       <hbj:textView id = "ll" text="lalalalalalalalalasasa" />
      <%--
    <hbj:textView id = "l">
                   <% l.setName(myBean1.getName());%>
    </hbj:textView>
    --%>
    <hbj:textView
                    id="appraisal_yr_label"
                    text="Apprasial Year:">
                    </hbj:textView>
                    <hbj:textView id = "la" >
                    <% la.setText(myBean1.getName());%>
                    </hbj:textView>
       </hbj:form>
      </hbj:page>
    </hbj:content>
    Beans1.java
    package Beans1;
    import java.io.Serializable;
    public class Bean1 implements Serializable{
    private String name = new String();
    private String e = new String();
    private String year = new String();
         public void setName(String name){
              this.name = name;
         public String getName(){
              return name;
    JSPDynPage
    import Beans1.Bean1;
    import com.sapportals.htmlb.*;
    import com.sapportals.htmlb.enum.*;
    import com.sapportals.htmlb.event.*;
    import com.sapportals.htmlb.page.*;
    import com.sapportals.portal.htmlb.page.*;
    import com.sapportals.portal.prt.component.*;
    public class testDBv5 extends PageProcessorComponent {
    import Beans1.Bean1;
    import com.sapportals.htmlb.*;
    import com.sapportals.htmlb.enum.*;
    import com.sapportals.htmlb.event.*;
    import com.sapportals.htmlb.page.*;
    import com.sapportals.portal.htmlb.page.*;
    import com.sapportals.portal.prt.component.*;
    public class testDBv5 extends PageProcessorComponent {
      public DynPage getPage(){
        return new testDBv5DynPage();
      public static class testDBv5DynPage extends JSPDynPage{
        private Bean1 myBean1= null;
        private String name = new String();
        public void doInitialization(){
              try{
                                  IntitialContext context = new javax.naming.InitialContext();
                                  DataSource dataSource = (DataSource)context.lookup("java:env/jdbc/appDB");
                                  Connection connection = dataSource.getConnection();
                                  Statement stmt = connection.createStatement();
                                  ResultSet rs = stmt.executeQuery("Select AppraisalYear From tblAppraisal Where AppraisalYear='2007'");
                                          while(rs.next()){
                                            year = rs.getString("AppraisalYear");
                                            rs.close();
                                            stmt.close();
                                            connection.close();
                                            return year;
                                       }catch (Exception n){
                                            n.printStackTrace();
              IPortalComponentProfile profile = ((IPortalComponentRequest)getRequest()).getComponentContext().getProfile();
                     Object o = profile.getValue("myBean1");
                     if(o==null || !(o instanceof Bean1)){
                        myBean1 = new Bean1();
                        profile.putValue("myBean1",myBean1);
                     } else {
                          myBean1 = (Bean1) o;
                        Object value = request.getSession().getValue("myBeans1");
                        if (value==null || (value instanceof Bean1)){
                             myBean1 = new Bean1();
                        request.getSession().putValue("myBean1", Object value);
              DataBase cn = new DataBase();
              name = cn.dataBaseConnection();
              myBean1.setName(name);
    //name = "gir";
    //myBean1.setName(name);
    // IPortalComponentRequest request = (IPortalComponentRequest) this.getRequest();
    //IPortalComponentContext myContext = request.getComponentContext();
    //Bean1 myNameContainer = (Bean1) myContext.getValue("myBean1");
    //myNameContainer.setName(name);
          // fill your bean with data here...
        public void doProcessAfterInput() throws PageException {
        public void doProcessBeforeOutput() throws PageException {
          this.setJspName("testDBv5.jsp");
    //testing purpose
      public static void main (String[] arg){
         testDBv5DynPage ef = new testDBv5DynPage();
               ef.doInitialization();
    Thanks Loads
    Quatre

  • Displaying Mysql data in JSPs...

    I am having problem displaying results that I am pulling from a Mysql table. When I test the code in a Java environment it works absolutely fine but when I transfer the code to a JSP it seems to execute it correctly but not display the output on the screen. The code I'm using is as follows.
    <%
    Class.forName("com.mysql.jdbc.Driver");
    Connection conn=DriverManager.getConnection(url,"root","111101");
    stmt = conn.createStatement();
    rs = stmt.executeQuery("SELECT * FROM student");
    while (rs.next()) {
    System.out.println(rs.getString("student_id")+"<br>");
    rs.close();
    catch( Exception x ) {
    x.printStackTrace();
    %>
    Any help on this topic would be much appreciated.

    My code now reads like this but I am still ahving the same problem -> I can't display the data being retrieved.
    <%@ page import="java.sql.*" %>
    <%
    String url = "jdbc:mysql://localhost/teaching";
    Statement stmt = null;
    ResultSet rs = null;
    %>
    <%@ taglib prefix="tags" tagdir="/WEB-INF/tags" %>
    <html>
    <head>
    <%
    Class.forName("com.mysql.jdbc.Driver");
    Connection conn=DriverManager.getConnection(url,"root","111101");
    stmt = conn.createStatement();
    rs = stmt.executeQuery("SELECT * FROM student");
    while (rs.next()) {
    System.out.println(rs.getString("student_id")+"<br>");
    %>
    <%=rs.getString("student_id")%>
    <hr>
    <%
    rs.close();
    catch( Exception x ) {
    x.printStackTrace();
    %>

  • 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 : )

  • How to Display jFrame - chart in JSP PAge

    Hi all,
    Can any one help about this task..
    I have writeen a java file which generates multiaxis chart by using JFreeChart API....
    Say for ex..
    public class multiaxis extends JFrame
    /// till know no problem...
    Can any one tell its possible to display this chart (JFrame) in Browser (JSP Page) .. any idea over this..
    Thanks in advance

    there's examples around the forums about using JFreeChart in a servlet to generate a JPEG or PNG images.

  • Dates in JSP page

    I have some dates fields on JSP page I want to store data in mysql databse. Can someone tell me how I can format dates as I do for other data types in servlet before I send data to add in databse: such as
    For int type data:
    String paymentID = request.getParameter("PaymentID")
    I format it like this for class Payment.
    Payment newPayment(int.parseInt(paymentID)               
    how do i work with date fields this is what I Am trying to do:
    Code patches....
    import java.text.DateFormat;\import java.text.ParseException;
    public date date1;
    try                               
          date1= format.parse(paymentStartDate);
    catch(ParseException pe)
    System.out.println("Problem found");
    ....I do not get any error but it leaves date fields empty because date1 formatting never goes to try... Always say "Problem found on console"
    Any help?

    I just realized I should post the whole file... here is code of the servlet that recieved dates from JSP and process it.
    package admin;
    import java.lang.Object.*;
    import java.text.DateFormat;
    import java.util.Date;
    import java.io.IOException;
    import java.text.ParseException;
    import data.*;
    import business.*;
    import javax.servlet.RequestDispatcher;
    import javax.servlet.ServletException;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    public class AddPaymentServlet extends HttpServlet{
         public Date date1;
         public Date date2;
        public DateFormat format;
         public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException{
    // Stores user entered Payment information in variables to create new Payment vector
              String paymentID = request.getParameter("paymentID");
              String clientName = request.getParameter("clientName");
             String paymentType = request.getParameter("paymentType");
              String paymentAmount = request.getParameter("paymentAmount");
             String paymentStartDate = request.getParameter("paymentStartDate");
              String paymentExpiryDate = request.getParameter("paymentExpiryDate");
              String paymentDescription = request.getParameter("paymentDescription");
              String paymentState1 = request.getParameter("paymentState"); // use String type of PaymentType
    //-----------------------------------Format dates----------------------------------------------------------          
             DateFormat format = DateFormat.getDateTimeInstance(DateFormat.MEDIUM,DateFormat.SHORT);
           //    System.out.println("Date1--->"+date1);
                  try
                       {    date1 = format.parse(paymentStartDate);
                        //    System.out.println("Date1--->"+date1);
                     catch(ParseException ps)
                            System.out.println("can't format dates");     
                      try
                       date2 = format.parse(paymentExpiryDate);
                  catch(ParseException pe)
                       System.out.println("can't format dates");
    // get old Payment object from session
    //--------------------------------Send new PAyment Information to Vector Payment in Payment.jave-----------------------------
              Payment newPayment = new Payment(clientName,paymentType,Double.parseDouble(paymentAmount),date1,date2,paymentDescription,paymentState1);
    //------------------------------ Call PaymentDB function Add() to store new payment infomration in the databse
             PaymentDB.addRecord(newPayment);
    // over-write Payment object in session
              request.getSession().setAttribute("payment",newPayment);
              request.getSession().setAttribute("payments",PaymentDB.readRecords());
    //---------------------------------- Send results back to payment.jsp for updated information----------------------
              RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/Admin/payments.jsp");
              dispatcher.forward(request, response);
         public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException{
              doGet(request, response);
    }

Maybe you are looking for

  • Black screen after updating to ios 8 iphone 4s

    iPhone 4S Cap 56,5 GB IOS 8.0.2 Model MD261HN/A Modem Firmware 5.4.00 Guys, since upgrade to IOS 8.0.0 I am getting black screens or crash in most apps (Facebook, Whatsapp, etc). That has never happened before and I own this phone for about 3 years.

  • HELP! QT file deteriorates around halfway when exporting for web

    I have an iMovie project that I have regularly exported to DVDs or other quicktime files: only when I export "for the web" this file (a 1G file that gets compressed to about 18MB for the web) deteriorates, starts to blur as if losing sync with the co

  • Run a batch file ones a month

    Hello there, i made a batch file and I want to run this batch file once a month on every client computer. is it possible to deploy the batch file with such an option? thanks in advance.

  • Retreiving latest IDOC number from Invoice number

    Hi, I am interested in retreiving latest IDOC number from a Invoice. Usually we have multiple IDOC numbers for same Invoice number. This is a report requirement. thank you. praveen

  • CS5.5 serial number doesn't work

    4 months ago I installed in my PC the CS5.5 by dialing the serial number of the product I purchased in the boxes of the splash screen of a trial version. All the programs of the CS have been installed as purchased products except for Fireworks (but I