• 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

servlets

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello
Good Afternoon.Iam new to servlet world.I have problem in passing parameters in web.xml.My program is:
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;


public class HelloWorldServlet extends HttpServlet
{
private String rate;

public void init() {
ServletConfig config = getServletConfig();
rate = config.getInitParameter("RATE1");
}

public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws IOException
{
response.setContentType("text/xml");
PrintWriter out = response.getWriter();

out.println("<html>");
out.println("<body>");
out.println("<h1>Hello World!</h1>");
out.println(" getRequestURI: " + request.getRequestURI());
out.println(" getServletPath: " + request.getServletPath());
out.println(" getPathInfo: " + request.getPathInfo());
out.println(" getConextPath: " + request.getContextPath());

out.println("</body>");
out.println("rate = ");
out.println(rate);

out.println("</html>");
}
}

my web.xml content looks like this:
<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">


<web-app>

<display-name>Test Servlet</display-name>
<description>
This is a simple test servlet.
</description>
<servlet>
<servlet-name>Hello World</servlet-name>
<servlet-class>com.HelloWorldServlet</servlet-class>
<init-param>
<param-name>RATE1</param-name>
<param-value>0.65</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>Hello World</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>


</web-app>
After running my servlet through url:http:\\localhost:8080\servlet\HelloWorldServlet i got the output as
- <html>
- <body>
<h1>Hello World!</h1>
getRequestURI: /servlet/HelloWorldServlet getServletPath: /servlet/HelloWorldServlet getPathInfo: null getConextPath:
</body>
rate = null
</html>


can anyone please help me???Iam getting null value for my parameter.Is there anything wrong in the way iam running the program?Please suggest me.
 
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

Is the culprit. That call goes through the invoker servlet - the invoker servlet does not pay any attention to your specific web.xml entry.
See the JavaRanch FAQ on the invoker.
Bill
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ankit,

Try running your application after making a small change in the XML

<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">


<web-app>

<display-name>Test Servlet</display-name>
<description>
This is a simple test servlet.
</description>
<servlet>
<servlet-name>Hello World</servlet-name>
<servlet-class>com.HelloWorldServlet</servlet-class>
<init-param>
<param-name>RATE1</param-name>
<param-value>0.65</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>Hello World</servlet-name>
<url-pattern>/Hello</url-pattern> {This is the URl With Which u will be calling the servlet.}
</servlet-mapping>

you can call the servlet in this way ::

http:\\localhost:8080\{ContextName}\Hello


Hope this solves your Query
 
Or we might never have existed at all. Freaky. So we should cherish everything. Even this tiny ad:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic