This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

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

 
Yashnoo lyo
Ranch Hand
Posts: 152
  • Mark post as helpful
  • send pies
  • 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
  • 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:
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!