• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Ranch Hand
Posts: 152
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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///////////////////////////////////
PageContext context=null;
DataSource ds=(DataSource)context.getAttribute(Action.DATA_SOURCE_KEYK);
conn=ds.getConnection();
stm=conn.createStatement();
rs=stm.executeQuery(insertsql);
Is right?But I get the "NullPointerException" error in Tomcat.I think the method that I get the context is not right.Had someone get the pagecontext in jsp page?help
:roll:
 
Yashnoo lyo
Ranch Hand
Posts: 152
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I change it to
DataSource ds=(DataSource)pageContext.getAttribute(Action.DATA_SOURCE_KEYK);
conn=ds.getConnection();
stm=conn.createStatement();
rs=stm.executeQuery(insertsql);
But the error remain
My struts-config.xml is:
/////////////////////////////////////////////////////
<data-sources>
<data-source type="org.apache.struts.util.GenericDataSource" 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 but not in jsp.I use struts1.1. Why? :roll:
reply
    Bookmark Topic Watch Topic
  • New Topic