felu
asked on
Servlet problem???
this is a very simple servlet code for SSI
//------------------------ ---------- -
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
public class ParameterServlet extends HttpServlet {
//Initialize global variables
private String company_name = null;
public void init(ServletConfig config)throws ServletException {
super.init(config);
company_name = getInitParameter("company" );
}
//Process the HTTP Get request
public void doGet(HttpServletRequest request,HttpServletRespons e response)throws ServletException, IOException {
response.setContentType("t ext/html") ;
PrintWriter out = response.getWriter();
out.println("<HTML>");
out.println("<TITLE>Parame ter Servlet</TITLE>");
out.println("<BODY>");
out.println("<H4>Company.. ..</H4>"+t his.compan y_name);
out.println("</BODY>");
out.println("</HTML>");
out.close();
}
}
//------------------------ ---------- ---
The html file for this is
<!------------------------ --->
<html>
<head>
<title>SSI-test</title>
</head>
<body bgcolor="#CFFFFC">
<servlet code=ParameterServlet Company="Yahoo">
</servlet>
</body>
</html>
<!------------------------ ---------- -->
and this is the output i get
Company....
null
as u see the company_name is null ie it is not reading that value in the parameter tag in the html file. What is the problem..
i am using jrun along with iis5.0 on win2k pro.
//------------------------
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
public class ParameterServlet extends HttpServlet {
//Initialize global variables
private String company_name = null;
public void init(ServletConfig config)throws ServletException {
super.init(config);
company_name = getInitParameter("company"
}
//Process the HTTP Get request
public void doGet(HttpServletRequest request,HttpServletRespons
response.setContentType("t
PrintWriter out = response.getWriter();
out.println("<HTML>");
out.println("<TITLE>Parame
out.println("<BODY>");
out.println("<H4>Company..
out.println("</BODY>");
out.println("</HTML>");
out.close();
}
}
//------------------------
The html file for this is
<!------------------------
<html>
<head>
<title>SSI-test</title>
</head>
<body bgcolor="#CFFFFC">
<servlet code=ParameterServlet Company="Yahoo">
</servlet>
</body>
</html>
<!------------------------
and this is the output i get
Company....
null
as u see the company_name is null ie it is not reading that value in the parameter tag in the html file. What is the problem..
i am using jrun along with iis5.0 on win2k pro.
you need change the line :
company_name = getInitParameter("company" );
to :
company_name = config.getInitParameter("c ompany");
then all will work, I hope
company_name = getInitParameter("company"
to :
company_name = config.getInitParameter("c
then all will work, I hope
ASKER
nope none of the above is working....
Juanan:
500 Internal Server Error
ParameterServlet: java.lang.NullPointerExcep tion:
yoavdo: it not working either.
Juanan:
500 Internal Server Error
ParameterServlet: java.lang.NullPointerExcep
yoavdo: it not working either.
Getting HTML form parameters is case sensitive; I wonder if that is the case here. I note that "Company" is capitalized in the <PARAM> tag and uncapitalized in your in your call to retrieve it.
ASKER
all initializing parameters are converted to lowercase when initialized. and i even tried with the uppercase 'C' .. it doesnot work ....
hi,
Actually , we'll set the initparameter using admin applet in javawebserver. Where you have option to set some initparametes like(key/value pair). By using getinitparameter("key or name of the parameter"); we get the value , which we stored using adming applet.
I dont know much of Jrun , certainly there will something set and get initparameter. check out.
Good Luck
Manjunath K
Actually , we'll set the initparameter using admin applet in javawebserver. Where you have option to set some initparametes like(key/value pair). By using getinitparameter("key or name of the parameter"); we get the value , which we stored using adming applet.
I dont know much of Jrun , certainly there will something set and get initparameter. check out.
Good Luck
Manjunath K
ASKER
thats ok manju but... doesnt that become specific.. ie if my page contains company="amazon" instead of "yahoo" i only get what the webserver has as its initparameters... i looked around for sometime in JRun but its not there ...... i think i will try to use apache with tomcat and see the results... felu
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
yeah i think i got it dotand.... but in th ebook i was using ie "Developing Java Servlets" by James Goodwill it said that the values can be passed from the HTML file... anyways thanx... all for replying...
On the doGet method you can write:
out.println ("<H4>Company....</H4>"
+ request.getParameterValues
modifying your servlet with this line
i think it must work.
Hope this helps.
Juanan.