Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

problem with web.xml and the getinitParameter() func

 
Preetham Chandrasekhar
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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....
 
Juanjo Bazan
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13061
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
See the ranch FAQ entry on the invoker.
Bill
 
VermaJitendra Verma
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 98
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<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
Posts: 98
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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....
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic