This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of Darcy DeClute's Scrum Master Certification Guide: The Definitive Resource for Passing the CSM and PSM Exams and have Darcy DeClute on-line!
See this thread for details.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Jeanne Boyarsky
  • Tim Cooke
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
Bartenders:

problem with web.xml and the getinitParameter() func

 
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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....
 
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
See the ranch FAQ entry on the invoker.
Bill
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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....
 
Onion rings are vegetable donuts. Taste this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic