• Post Reply Bookmark Topic Watch Topic
  • New Topic

Unusual problem with config.getInitParameter  RSS feed

 
Anna Ferrari
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

this is my situation:

web.xml

<context-param>
<param-name>driv</param-name>
<param-value>org.gjt.mm.mysql.Driver</param-value>
</context-param>
<context-param>
<param-name>url</param-name>
<param-value>jdbc:mysql://localhost/RM_archit</param-value>
</context-param>
<context-param>
<param-name>usr</param-name>
<param-value>java</param-value>
</context-param>
<context-param>
<param-name>pas</param-name>
<param-value>java</param-value>
</context-param>


servlet:

public class SrvMenu extends HttpServlet {


String driv=null;
String url=null;
String usr=null;
String pas=null;

public void init (ServletConfig config) throws ServletException {
super.init(config);
driv=config.getInitParameter("driv");
url=config.getInitParameter("url");
usr=config.getInitParameter("usr");
pas=config.getInitParameter("pas");
}



public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {

.....
.....
myconn=x.openDBase(driv, url, usr, pas);
.....

I call servlet but don't work, and worse yet my computer overheats (in task manager windows: java.exe goes 99% CPU and javaw.exe goes also up)
(For information I use Jboss 4.0.2, java 1.5).
Any suggestion?

Thanks in advance.
 
Scott Selikoff
author
Bartender
Posts: 4081
21
Eclipse IDE Flex Google Web Toolkit
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you know which line it hangs on? Try adding debugging statements to determine this.
 
Anna Ferrari
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, Scott
and thanks for your suggestion.
With debug I see :
x.openDBase(null, null, null, null).
Because this don't work :

driv=config.getInitParameter("driv");
url=config.getInitParameter("url");
usr=config.getInitParameter("usr");
pas=config.getInitParameter("pas");

Why?
How can I do?
Thanks.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're using the wrong method.

The getInitParam() method on the servlet config will return the init parameters defined for that servlet.

Since it is context parameters that you are trying to fetch, you'll need to use the getInitParam() method on the ServletContext instance.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And Anna, in the future please use UBB code tags when you post code. Thanks.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also highly recommend over-riding the init() method rather than init(ServletConfig).
 
Anna Ferrari
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Bear.

I revolve my problem in this mode in side init (ServletConfig config):

//super.init(config);

Is it also correct then over-riding the init() method ?

Bye and thanks.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!