aspose file tools*
The moose likes Servlets and the fly likes problem with web.xml and the getinitParameter() func Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "problem with web.xml and the getinitParameter() func" Watch "problem with web.xml and the getinitParameter() func" New topic
Author

problem with web.xml and the getinitParameter() func

Preetham Chandrasekhar
Ranch Hand

Joined: Nov 05, 2003
Posts: 98
hi all,
I have my code below and Im not sure for what reason it isnt working! I did change my web.xml in the WEB-INF directory as well to contain the servlet name and the init-param and its corresponding values. However when
I try running the servlet....it gives the 404 error.
I have the code and the web.xml extract below...
//code
package coreserv;
//imports
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class InitParams extends HttpServlet implements SingleThreadModel{
private String message;
boolean debug;
private int repeats = 1;
private String defaultMessage = "No Message";
public void init() throws ServletException{
message = getInitParameter("message");
if(message==null){
message = defaultMessage;
}
try{
String repeatString = getInitParameter("repeats");
repeats = Integer.parseInt(repeatString);
}catch(NumberFormatException nfe){

}

}
public void toGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
response.setContentType("text/html");
PrintWriter out = response.getWriter();
String title = "The Message shown:";

out.println(ServletUtilities.HeadWithTitle(title) + "<BODY><H1>" + title + "</H1>");
for(int i=0;i<repeats;i++){
out.println(message + "<BR>");

}
out.println("</BODY></HTML>");


}
}

//web.xml...from /examples/WEB-INF/web.xml
<servlet>
<servlet-name>
InitParams
</servlet-name>
<servlet-class>
coreserv.InitParams
</servlet-class>
<init-param>
<param-name>message</param-name>
<param-value>Shibboleth</param-value>
</init-param>
<init-param>
<param-name>repeats</param-name>
<param-value>5</param-value>
</init-param>
</servlet>

and I type in
http://localhost:xxxx/examples/servlet/InitParams
or
http://localhost:xxxx/examples/servlet/coreserv.InitParams
both dont work..... :-(
I also tried this in init(ServletConfig config){} method as well...but no luck!!!
any suggestions?
any suggesstions....


"In theory, there is no difference between theory and practice. But, in practice, there is."<br /> - Jan L.A. van de Snepscheut
Juanjo Bazan
Ranch Hand

Joined: Feb 04, 2002
Posts: 231
Using the /servlet/ pattern means you want to use the invoker servlet which probably is disabled by default in your server(check the web.xml of the server's configuration).
HTH
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12806
    
    5
See the ranch FAQ entry on the invoker.
Bill
VermaJitendra Verma
Greenhorn

Joined: Apr 15, 2004
Posts: 2
Hello there
let us know if the exmaple u are running is on WIN or Linux.
If it is linux then check your rights on the particular fiel. It happened to me in linux.
Regards
Verma
Preetham Chandrasekhar
Ranch Hand

Joined: Nov 05, 2003
Posts: 98
<servlet>
<servlet-name>invoker</servlet-name>
<servlet-class>org.apache.catalina.servlets.InvokerServlet</servlet-class>
<init-param>
<param-name>debug</param-name>
<param-value>0</param-value>
</init-param>
<load-on-startup>2</load-on-startup>
</servlet>
this is what is in my conf/web.xml invoker servlet and it is not commented....but still it isnt wrking...and this is being done on windows(sadly).
Preetham Chandrasekhar
Ranch Hand

Joined: Nov 05, 2003
Posts: 98
hi guys,
got it resolved....it was so stupid...instead of doGet() in the above code i put in toGet()..... wasted hours figuring out this...sorry to take ur time as well....
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: problem with web.xml and the getinitParameter() func