Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I have an error with ServletConfig!!!

Status
Not open for further replies.

outis

Programmer
Jun 20, 2001
21
MX
The error is that de servlet doesn't read the SimpleInitFile.servlet because the servlet returns null when it read de parameters. here is de code and the xml file
I will appreciate your help

the servlet....

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class SimpleInitServlet extends HttpServlet {

public String mydriver;
public String myurl;
public String myuserID;
public String mypassword;

public void doGet(HttpServletRequest req, HttpServletResponse res)throws ServletException, IOException {
...

}


// i dont see what is wrong
public void init(ServletConfig config) throws
ServletException {
super.init(config);
mypassword = config.getInitParameter("password");
mydriver = config.getInitParameter("driver");
myuserID = config.getInitParameter("userID");
myurl = config.getInitParameter("URL");

}
}

the xml file.....

<?xml version=&quot;1.0&quot;?>
<servlet>
<code>SimpleInitServlet</code>
<init-parameter value=&quot;dspaduntj&quot; name=&quot;password&quot;/>
<init-parameter value=&quot;com.ibm.as400.access.AS400JDBCDriver&quot; name=&quot;driver&quot;/>
<init-parameter value=&quot;userid&quot; name=&quot;userID&quot;/>
<init-parameter value=&quot;jdbc:as400://143.12.11.168&quot; name=&quot;URL&quot;/>
<init-parameter value=&quot;jdbc/jdbcas400135215178&quot; name=&quot;dataSourceName&quot;/>
</servlet>
 
Your deployment descriptor is wrong. You need to follow the structure for deployment descriptors exactly if you want them to work. It should look like this:
[/code]
<!DOCTYPE web-app PUBLIC &quot;-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN&quot; &quot;<web-app>
<servlet>
<servlet-name>SimpleInitServlet</servlet-name>
<servlet-class>Fully Qualified Class</servlet-class>
<init-param>
<param-name>password</param-name>
<param-value>dspaduntj</param-value>
</init-param>
<init-param>
<param-name>driver</param-name>
<param-value>com.ibm.as400.access.AS400JDBCDriver</param-value>
</init-param>
<init-param>
<param-name>userID</param-name>
<param-value>userid</param-value>
</init-param>
<init-param>
<param-name>URL</param-name>
<param-value>jdbc:as400://143.12.11.168</param-value>
</init-param>
<init-param>
<param-name>dataSourceName</param-name>
<param-value>jdbc/jdbcas400135215178</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>SimpleInitServlet</servlet-name>
<url-pattern>/SimpleInitServlet</url-pattern>
</servlet-mapping>
</web-app>
[/code]

Of course some of this information you need to support like the FQ Class and other information is really up to you like the servlet-mapping.

I suggest you check out the DTD for a Web Application Deployment Descriptor, here is the link: Wushutwist
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top