How can I get the "pageContext" object in jsp page?

Hi everyone:
I want to get struts's DataSource object in jsp page.So I should get the PageContext object in jsp page.My code is:
///////////////////datatest.jsp///////////////////////////////////
     DataSource ds=(DataSource)pageContext.getAttribute(Action.DATA_SOURCE_KEY);
     conn=ds.getConnection();
          stm=conn.createStatement();
          rs=stm.executeQuery(insertsql);
Is right?But I get the "NullPointerException" error in Tomcat.The connection pool in struts-config.xml is:
<data-sources>
<data-source key="mydatasource">
<set-property property="autoCommit"
value="false"/>
<set-property property="description"
value="MyWebSite Data Source Configuration"/>
<set-property property="driverClass"
value="org.gjt.mm.mysql.Driver"/>
<set-property property="maxCount"
value="4"/>
<set-property property="minCount"
value="2"/>
<set-property property="password"
value="qijiashe"/>
<set-property property="url"
value="jdbc:mysql://localhost:3306/myweb"/>
<set-property property="user"
value="lyo"/>
</data-source>
</data-sources>
I can query the database in servlet.
I think the method that I get the context is not right.Had someone get the pagecontext in jsp page?help :(

Sorry I forgot that I had change the code:
DataSource ds=(DataSource)pageContext.getAttribute(Action.DATA_SOURCE_KEY);
     conn=ds.getConnection();
          stm=conn.createStatement();
          rs=stm.executeQuery(insertsql);
to the code:
DataSource ds=(DataSource)pageContext.getAttribute("mydatasource");
     conn=ds.getConnection();
          stm=conn.createStatement();
          rs=stm.executeQuery(insertsql);
mydatasource is the struts datasource in "struts-config.xml". I couldn't work

Similar Messages

  • How can I get the underlying object from the ObjectReference

    Dear friends,
    I think this question has been asked a couple of times. But, I am still wondering if anybody has found an answer to it. Maybe this is some common need ...
    I would like to get the underlying object for which the ObjectReference is
    a mirror For example, I have a class Customer in my application, and I can get an ObjectReference through JDI during runtime. But how can I get the target VM's object which is a real instance of Customer, by which I can invoke methods defined in Customer?
    Thank you so much for any input!
    SunnyDay

    I'll preface this response by admitting this far from an elegant solution, but I did write a function addressing this question, mostly as an exercise.
    If passed an object with an InTextFrame property (Pgf, AFrame, Cell, Fn) that resides in an open document, the function will return the Doc object. Otherwise, it returns undefined.
    function getParentDoc(testObj) {
        //Get object for current page
        try { var curPage = testObj.InTextFrame.FrameParent.PageFramePage; }
        catch(er) {return;}
        //Step backwards to first page in document
        var prevPage = curPage.PagePrev;
        while (prevPage.ObjectValid())
            curPage = prevPage;
            prevPage = prevPage.PagePrev;
        //Compare with first pages of open documents
        var testDoc = app.FirstOpenDoc;
        while (testDoc.ObjectValid())
            if (curPage.id==testDoc.FirstBodyPageInDoc.id) return testDoc;
            testDoc = testDoc.NextOpenDocInSession;    
        return;
    To your PPS: Rather than seeing the native framework grow bloated to address additional features, I would love to see Adobe and other developers publish libraries of useful functions and class extensions.

  • How do I get the bean property to JSP page for use in a Scriplet

    Hi all,
    I am new to JSF and would like to know how can I get the Bean property to a JSP page and then use that property to dynamically display the contents.
    Thank in advance,

    Hi,
    I think the following page will be helpfull.
    http://java.sun.com/developer/technicalArticles/javaserverpages/JSP20/
    Akif

  • How can I get the Doc object from any other object?

    Dear colleagues,
    in FrameScript it is dead-simple to get to the document part of any object, just add .Doc to the variable.
    How can I achieve the same with ExtendScript? I amtired of passing the document object next to AFrames or Pgfs along into subroutines, because those objects already contain the information about their document. But how do I access this?
    Thanks for pointers,
    - Michael
    PS: Almost the same is true for the page an object lives on. With FrameScript we use .Page, with ExtendScript you have to move up the object tree until you reach the UnanchoredFrame.PageFramePage…
    PPS: It would be great to see some convenience properties like .Doc and .Page implemented natively.

    I'll preface this response by admitting this far from an elegant solution, but I did write a function addressing this question, mostly as an exercise.
    If passed an object with an InTextFrame property (Pgf, AFrame, Cell, Fn) that resides in an open document, the function will return the Doc object. Otherwise, it returns undefined.
    function getParentDoc(testObj) {
        //Get object for current page
        try { var curPage = testObj.InTextFrame.FrameParent.PageFramePage; }
        catch(er) {return;}
        //Step backwards to first page in document
        var prevPage = curPage.PagePrev;
        while (prevPage.ObjectValid())
            curPage = prevPage;
            prevPage = prevPage.PagePrev;
        //Compare with first pages of open documents
        var testDoc = app.FirstOpenDoc;
        while (testDoc.ObjectValid())
            if (curPage.id==testDoc.FirstBodyPageInDoc.id) return testDoc;
            testDoc = testDoc.NextOpenDocInSession;    
        return;
    To your PPS: Rather than seeing the native framework grow bloated to address additional features, I would love to see Adobe and other developers publish libraries of useful functions and class extensions.

  • How can I stop the execution on a JSP page and start it again

    Hi
    I am making a program that simulates how to manage transactions when accessing a database by using locks. I have run into a problem and I hope someone has the time to help me.
    When a user does an update the transaction commits and releases its locks when the program executes
    <%stmt.executeUpdate("commit!"); %>
    I need to put a break in to stop the program executing this statement, to illustrate the lock is set correctly.
    I have tried to put in an alert box but this does not prevent the rest of the java code being executed.
    I have tried to use prompt boxes, JavaScript functions, but these functions cannot have any java code in them.
    I have tried using the java.swing JOptionPane boxes but this didn?t work either
    I have tried to get input from the user but I don?t know how to retrieve this data on the same page. (As far as I know you have to use submit and even refresh the page or retrieve it on the next page).
    Does anyone know how I can stop the execution on a JSP page and start it again (on same page)
    Mette

    I already have another client (Tomcat jsp application) running and it throws a SQLException correctly when I don�t put in a commit=true statement and don't close the database connection.
    But the problem is how to get the code above to stop to illustrate I have set this lock.
    I have tried to use the JOptionPane but because my program is running in a web browser I cannot use the JOptionPane dialog box.
    I have tired using an alert box but it executes the commit statement before the alert box is dispayed. So this does not work
    While (i < 2)
    if( i==1)
    %>alert(�The transactions commits when you press Ok�); <% //what it to stop execution here
    else
    stmt.executeUpdate(�commit�);
    I am not using threads so I cannot use the sleep function.
    I am using mysql and have already configured it to detect deadlocks and how long to wait for locks.
    Thanks for your help
    Mette

  • How do I get the URL of a jsp page which calls a servlet?

    I have a jsp page which will lead to a servlet, I can get the URL of the servlet, but how do I get the URL of the jsp page which lead to the Servlet in the servlet?

    You could try doing:
    request.getHeader("Referer");

  • How can i get the values from one JSP to another JSP

    Hi All,
    I am very new to JSP technology, I have one jsp having radio button, i want to accecc the state of this radio button to another JSP page, How can i do this.
    Could anybody help me.
    with Regards
    Suresh

    Try page import <%@ page import ="index.jsp" %> or include <%@include file="index.jsp" %> methods perhaps they might work.

  • How can i get the full URL of a page displayed rather than just the main website URL

    I'm using Safari 8.0 on an iMac.  When I go to a website I'm used to seeing a specific page URL displayed /changing as I navigate around a site through its various subsections etc. Now after updating to Yosemite all I get is the URL of the general website. This means I can't make specific references/links in work that I'm doing/sharing. There must surely be a way of  getting the info into the bar so that I can copy it .... can anyone help please?

    Jorge Huedo wrote:
    > Yeah i know it was because i was getting crazy and i wanted to see debuggin if the image really existed in the km.
    > Okey I have use the IUrlGeneratorService like this.
    >
    >      IURLGeneratorService ugs = (IURLGeneratorService) ResourceFactory.getInstance().getServiceFactory().getService(IServiceTypesConst.URLGENERATOR_SERVICE);
    >      IUriReference uriRef;
    >      uriRef = ugs.getRelativeUri(PathKey.IMAGE_PATH).appendPath(
    >      resourceimg.getRID().toExternalForm());
    >
    > And it has returned me the next url:
    >
    > irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/etc/public/mimes/images/pip_hesaeventos/blank.JPG
    >
    > Now i have added to the base of the server the url:
    >
    > http://altp4.es.heiway.net:54500/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/etc/public/mimes/images/pip_hesaeventos/blank.JPG
    >
    > And the return is:
    >
    > 404
    > El recurso solicitado no está disponible.
    >
    > Any idea?
    You need to use the propert PathKey; I think CONTENT_ACCESS should be correct.

  • How can I get the Error place in JSP rapidly?

    The Error is:
    <h1>Error: 500</h1>
    <h2>Location: /members/subscribe.jsp</h2><b>Internal Servlet Error:</b><br><pre>javax.servlet.ServletException: No data found
         at org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:459)
         at members._0002fmembers_0002fsubscribe_0002ejspsubscribe_jsp_4._jspService(_0002fmembers_0002fsubscribe_0002ejspsubscribe_jsp_4.java:220)
         at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:119)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
         at org.apache.jasper.servlet.JspServlet$JspServletWrapper.service(JspServlet.java:177)
         at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:318)
         at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:391)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
         at org.apache.tomcat.core.ServletWrapper.doService(ServletWrapper.java:404)
         at org.apache.tomcat.core.Handler.service(Handler.java:286)
         at org.apache.tomcat.core.ServletWrapper.service(ServletWrapper.java:372)
         at org.apache.tomcat.core.ContextManager.internalService(ContextManager.java:797)
         at org.apache.tomcat.core.ContextManager.service(ContextManager.java:743)
         at org.apache.tomcat.service.http.HttpConnectionHandler.processConnection(HttpConnectionHandler.java:210)
         at org.apache.tomcat.service.TcpWorkerThread.runIt(PoolTcpEndpoint.java:416)
         at org.apache.tomcat.util.ThreadPool$ControlRunnable.run(ThreadPool.java:498)
         at java.lang.Thread.run(Thread.java:484)
    </pre>
    <b>Root cause:</b>
    <pre>java.sql.SQLException: No data found
         at sun.jdbc.odbc.JdbcOdbc.standardError(JdbcOdbc.java:6212)
         at sun.jdbc.odbc.JdbcOdbc.SQLGetDataInteger(JdbcOdbc.java:3171)
         at sun.jdbc.odbc.JdbcOdbcResultSet.getDataInteger(JdbcOdbcResultSet.java:5317)
         at sun.jdbc.odbc.JdbcOdbcResultSet.getInt(JdbcOdbcResultSet.java:548)
         at members._0002fmembers_0002fsubscribe_0002ejspsubscribe_jsp_4._jspService(_0002fmembers_0002fsubscribe_0002ejspsubscribe_jsp_4.java:124)
         at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:119)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
         at org.apache.jasper.servlet.JspServlet$JspServletWrapper.service(JspServlet.java:177)
         at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:318)
         at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:391)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
         at org.apache.tomcat.core.ServletWrapper.doService(ServletWrapper.java:404)
         at org.apache.tomcat.core.Handler.service(Handler.java:286)
         at org.apache.tomcat.core.ServletWrapper.service(ServletWrapper.java:372)
         at org.apache.tomcat.core.ContextManager.internalService(ContextManager.java:797)
         at org.apache.tomcat.core.ContextManager.service(ContextManager.java:743)
         at org.apache.tomcat.service.http.HttpConnectionHandler.processConnection(HttpConnectionHandler.java:210)
         at org.apache.tomcat.service.TcpWorkerThread.runIt(PoolTcpEndpoint.java:416)
         at org.apache.tomcat.util.ThreadPool$ControlRunnable.run(ThreadPool.java:498)
         at java.lang.Thread.run(Thread.java:484)
    </pre>
    I can not get Any Info that can help me to debug!

    You can look in the generated servlet file, somewhere in
    your webserver (tomcat?) directories:
    _0002fmembers_0002fsubscribe_0002ejspsubscribe_jsp_4.java:220
    On the line 220 there is the error.
    The root cause is:
    <b>Root cause:</b>
    <pre>java.sql.SQLException: No data found
    That should help, to find the error.
    Regards,
    Geri

  • How can i get the variable declared in jsp to a javascript function

    Hello all.
    I'm in a trouble.. i was developing a program in jsp oracle. and in some cases i use java scripts.. here in the HR program module i feel a trouble.
    the code here i'm sending is just a trial one.. the jdbc and all are doing in the jsp page itslef.
    egs.. : there is a table with 4 fields
    Empid Empname Empdetails EmpSal
    and in the table there are 100 records. Emp id is the primary key
    here what my problem starts..
    i want to list all the emp id in the combo box
    for that i used jsp program
    now when i select any one emp id i want to display the
    empname emp details and emp salary in another 3 text boxes
    i have successfully placed all the empid in the combo box
    now what i done is i wrote code in java script.. in onchange() for combo
    now i'm not getting the values
    here i'm sending the code.. below..
    please help me
    <html>
    <head>
    <title>DOLOGIN
    </title>
    </head>
    <%@ page language="java" session="true" import="java.sql.*" %>
    <body>
    <form method="POST" name="form1" action="--WEBBOT-SELF--">
         <!--webbot bot="SaveResults" U-File="fpweb:///_private/form_results.csv" S-Format="TEXT/CSV" S-Label-Fields="TRUE" -->
    <select size="1" name="D1" onchange =xx() >
    <option> Select One</option>
    <%
    String age[] = new String[20];
    String ph[] = new String[20];
    int i=0;     
    try
         try
         {     Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
         catch(ClassNotFoundException e)
         {     out.println(e);
              String dbURL = "jdbc:odbc:trial";
              Connection dbCon;
              dbCon = DriverManager.getConnection(dbURL);
              String query = "Select * from table1";
              Statement stmt = dbCon.createStatement();
              ResultSet rs = stmt.executeQuery(query);
              while(rs.next())
              {     String name = rs.getString(1);
                   //out.println(name);
                   %>
                   <option value="<%=name%>"><%=name%></option>
                   <%
                   age= rs.getString(2);
                   ph[i] = rs.getString(3);
                   //out.println(age[i]);
                   //out.println(ph[i]);
                   i++;
         %>
         </select>
         <%
              out.println(age[4]);
              dbCon.close();
              stmt.close();
    catch(SQLException e)
    {     response.sendRedirect("error.html");
    %>
    </form>
    </body>
    </html>
    <SCRIPT LANGUAGE=javascript>
    <!--
    function xx()
    {     //alert("aravind")     
         alert(document.form1.D1.selectedIndex)
         alert(document.form1.D1.value)
         alert(age[document.form1.D1.selectedIndex]) //this is not executing//
    //-->
    </SCRIPT>
    here is the code..
    i want the age to run here
    please help me

    To ensure a custom ordering, sort the files in an album and rename the files with a sequentially numbered filename.
    File > Export > Version/Originals
    Then use "Filename > Sequential"
    or "Filename > Album name with index"

  • How can I display the date on a jsp page??

    Is there anyway to display the current date when someone views a jsp page??? Can I get it from the server or something like that?
    Thx
    Rich

    is there any type of formatting that goes witth
    that.....Most definitely -- check out the java.text.DateFormat object and its cohort java.text.SimpleDateFormat.
    For example, if you wanted to display the current date in MM/DD/YYYY format, you could do the following:
    <%-- This could go somewhere near the top of the JSP %>
    <%
    SimpleDateFormat f = new SimpleDateFormat("MM/dd/yyy");
    %>
    <% And later on, you could have... %>
    <%= f.format(new Date()); %>Note that I've omitted the proper <%import%> directives.
    -Navin

  • How do I get the URL of a jsp page?

    I have a jsp page which has a link to a servlet page, in the servlet page, I want to get the URL of the jsp page.
    I tried to use request.getHeader("referer"), it seems like if it is a link in the jsp directly lead to the servlet, it works, but if the link calls a javascript function which opens up a window runing the servlet, it is not working. I have to do the second way, so it is not working by doing request.getHeader("referer")
    I tried to use javascript "location.href", I get the whole url by alerting the url in the jsp page:
    http://localhost:8080/pos-webapp/serv/qt_old?currentpage=portal&bcd=ABC123&pnm=P1001830&prnm=1&psd=236863.0&ln=01&sln=NYPPA&stp=2.1&stt=A&_POSID=1F8464122ADAF4EEC9B1A94C286EB252
    then I pass this url when calling with my servlet, in the servlet page, when I do request.getParameter("url"), the url is actually cut off like this:
    http://localhost:8080/pos-webapp/serv/qt_old?currentpage=portal
    anything after &pnm is cut off, anyone has any idea?
    Thanks in advance.

    Thank you.
    but how do I put encoding in the javascript code? do I need to decode in my servlet page?
    here is my code in the jsp page:
    linkset[3]+='<div class="menuitems">Email Diagnostics to AutoOne</div>'<%     
    function emailDiagnostics()
    win = window.open("/pos-webapp/serv/email_diagnostics?url=" + location.href + "&browser=" + navigator.appName, "emailDiagnostics",
    "width=350, height=140, resizable=no, scrollbars=no, toolbar=no, location=yes, directories=no, status=no, menubar=no, copyhistory=no, left=450, top=300");
    win.focus();
    }

  • How can i get the unitOfWork or the persisting object in to my listener???.

    hi,
    i have a listener class which extends SessionEventAdapter ....as shown below
    public class MyLister extends SessionEventAdapter{
    public void postCommitUnitOfWork(SessionEvent event) {
    System.out.println("POST COMMIT OF WORK");
    // How can i get the unitOfWork or the persisting object in to my listener???
    Another class makes use of this listener by adding the listener into a getEventManager() of a session ....
    public final class AetbProcessStatusClient {
    public static final void main(String[] args)
    {  Project project =   
    XMLProjectReader.read("META- INF/AetbProcessStatus.xml",
    Thread.currentThread().getContextClassLoader());
    DatabaseSession session = project.createDatabaseSession();
    MyLister myListener = new MyLister();
    session.getEventManager().addListener(myListener);
    session.login();
    UnitOfWork uow = session.acquireUnitOfWork();
    uow = session.acquireUnitOfWork();
    Vector vec =
    (Vector)uow.executeQuery("SQFunctionIdProcessStatus", AetbProcessStatus.class);
    AetbProcessStatus processStatus = new AetbProcessStatus();
    processStatus = (AetbProcessStatus)vec.get(0);
    processStatus.setRunStat('E');
    processStatus.setProgramSeqNo(10);
    uow.commit();
    now my question --> How can i get the unitOfWork or the persisting object in to my listener???....
    ie the object "processStatus" into my listener

    The SessionEvent's session (getSession()), should be the UnitOfWork. You can access the UnitOfWork or UnitOfWorkImpl methods to access the objects in the unit of work. getUnitOfWorkChangeSet() will return the changes made in the UnitOfWork.
    -- James : http://www.eclipselink.org

  • How can i get the value stored in the session object using its sessionid

    how can i get the value stored in the session object using its sessionid by running stand alone java application

    myforum wrote:
    how can i get the value stored in the session object using its sessionid by running stand alone java applicationThis does not seem to make sense! You need at least to give a lot more detail of what you are doing.

  • How can I get the X and Y coordinates of an object in Xcode, ApplescriptObjc?

    How can I get the value of a specified object's X and Y coordinates in Xcode, using ApplescriptObjc? I'm hoping for something like:
    myObject's currentPosition()
    // Which would return {150, 100} for the X and Y of that object.

    Actually this is straight from basic physics
    Assuming that the x and y values you get using that AppleScript/Objective-C code is accurate, to move the object you would do
    set x to x + dx * speed
    set y to y + dx * speed
    with dx and dy being an integer with a value of -1 or 1 which indicates the direction the object is moving. Remember the origin in OS X is the middle of the frame or screen with positive x and y values moving to the upper right quadrant, and negative x and y values moving to the lower left. Your basic Cartesian coordinate system. Speed is also an interger and models the speed of the object.
    Once you've set x and y to their new values you would write  them back to the object.
    This is so I can find how much distance (in pixels) is being travelled when I animate an object to move from one position to another, to apply it to my desired velocity (of pixels per second), to find out how long the object should take to move.
    This part has got me stumped.
    To make an object move you need to change its x and y coordinates. To get smooth animation you need to change them on a regular schedule at a rate fast enough to avoid jerky motion. Given the refresh rate of most monitors and other factors a rate of 60 times per second gives good results. Between each tick of the clock you change the x and y coordinates by some amount, the size of the amount will model speed. Add a small change and the object moves slowly, add a big amount and the object moves quickly. Keep the amount of change constant and the object will move at a constant speed. Increase (or decrease) the amount of change between each tick and the object will accelerate (or decelerate)

Maybe you are looking for

  • How to change the channel on your router.

    > this is for 10.7.4 Open Airport tuility on your comtpuer where to find it > :  Applications folder > utilities > airport utility Clicked the apple router > click the edit button Clicke the wirless tab at the top and choose wirless options at the bo

  • External optical drive not found by iMac?

    Just purchased an LG Mac Compatible Slim Portable DVD Writer to use with my 2011 iMac because I replaced the internal optical drive with an SSD drive. When I connect the drive via USB I get an initialization error. Any suggestions as to what might wo

  • Resolving a variable in an equation...

    Hi All The problem is this: e.g. (3-(4*a)/4 = 40 I need to be able to calculate what 'a' is. I have converted the left hand side of the equation to rpn but cannot work out how that will help me at the moment. The example is simply that, I could have

  • How do I create a new Aperture library from pictures I moved from IMAC?

    I moved my Photos to External Hard drive from MAC . Can I create new aperture library in EHD?

  • Droid X Contacts Problem

    This problem has to do with Contacts being displayed consistently between the various APS that use them. These all worked fine and as expected until I shut down the phone.  The problem started and remains after turning the phone back on.  All my cont