Solved

Servlet problem???

Posted on 2000-05-06
9
305 Views
Last Modified: 2013-11-24
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,HttpServletResponse response)throws ServletException, IOException {
    response.setContentType("text/html");
    PrintWriter out = response.getWriter();
      
out.println("<HTML>");
out.println("<TITLE>Parameter Servlet</TITLE>");
out.println("<BODY>");
out.println("<H4>Company....</H4>"+this.company_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.

0
Comment
Question by:felu
9 Comments
 

Expert Comment

by:juananmm
ID: 2784151
I think you must retrieve the company name on the doGet method unless init.

On the doGet method you can write:

out.println ("<H4>Company....</H4>"
+ request.getParameterValues("company")[0]);

modifying your servlet with this line
i think it must work.


Hope this helps.

Juanan.
0
 

Expert Comment

by:yoavdo
ID: 2785373
you need change the line :
company_name = getInitParameter("company");
to :
company_name = config.getInitParameter("company");

then all will work, I hope
0
 

Author Comment

by:felu
ID: 2785422
nope none of the above is working....
Juanan:
500 Internal Server Error
ParameterServlet: java.lang.NullPointerException:

yoavdo: it not working either.

0
 

Expert Comment

by:el_ouhd
ID: 2785913
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.
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 

Author Comment

by:felu
ID: 2785961
all initializing parameters are converted to lowercase when initialized. and i even tried with the uppercase 'C' .. it doesnot work ....
0
 

Expert Comment

by:manjucee
ID: 2787272
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
0
 

Author Comment

by:felu
ID: 2788043
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
0
 
LVL 1

Accepted Solution

by:
dotand earned 20 total points
ID: 2791284
Hi,

getInitParameter does not read the parameter from the HTML file. Rather it asks the servlet runner to look into it's own parameter files to check if there has been a parameter named "company" passed to your servlet, you will have to manually add the parameter to these files.

If you want the parameter to be passed as part of the URI you have several options, including an invisible form or hard-coding the parameter into the URL:
http://server:port/servelt?comapny=name
And then use the getParameter method in HttpServletRequest.

HTH,
Dotan
0
 

Author Comment

by:felu
ID: 2795384
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...
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
mockito example issue 8 62
java 8 lambda expresssions exception handling 3 75
Java JRE greater than 1.6 5 50
reverse digits of a number using for loop 5 36
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now