File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes servlets Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "servlets" Watch "servlets" New topic
Author

servlets

ankita balaji
Greenhorn

Joined: Aug 19, 2004
Posts: 11
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.
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12783
    
    5

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
Ajosh Gopi
Greenhorn

Joined: Aug 23, 2004
Posts: 1
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: servlets