• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

getting Error in retrieving CGI variables

 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here is code to servlet i used. i am getting errors like incompatible type of declaration. Can't convert int to java.lang.integer...


-----------------------------------------------------------------
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.http.HttpServletRequest;
import java.lang.*
import java.util.*;
public class Cgi extends HttpServlet
{
public void doGet (HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
String Authorization = request.getAuthType();
Integer Content_len = request.getContentLength();
String Doc_root = request.getRealPath("/");
Integer Server_port = request.getServerPort();
String Server_software = getServletContext().getServerInfo();
//PrintWriter out;
// set content type and other response header fields first
response.setContentType("text/html");
// then write the data of the response
PrintWriter out = response.getWriter();
out.println("<html>");
out.println("<head>");
out.println(" <title>Servlet: Showing CGI Variables</title>");
out.println("</head>");
out.println("<body bgcolor=\"#FFFFFF\">");
out.println("<table width=\"75%\" border=\"1\">");
out.println("<tr>");
out.println(" <td width=\"51%\">Authorization</td>");
out.println(" <td width=\"49%\">" + Authorization + "</td>");
out.println(" </tr>");
//out.println("<tr>");
//out.println(" <td width=\"51%\">Content_len</td>");
//out.println(" <td width=\"49%\">" + Content_len + "</td>");
//out.println(" </tr>");
out.println("<tr>");
out.println(" <td width=\"51%\">Doc_root</td>");
out.println(" <td width=\"49%\">" + Doc_root + "</td>");
out.println(" </tr>");
//out.println("<tr>");
//out.println(" <td width=\"51%\">Server_port</td>");
//out.println(" <td width=\"49%\">" + Server_port + "</td>");
//out.println(" </tr>");
out.println(" <tr>");
out.println(" <td width=\"51%\">Server_software</td>");
out.println(" <td width=\"49%\">" + Server_software + "</td>");
out.println(" </tr>");
out.println("</table>");
out.println("</body>");
out.println("</html>");
out.close();
}
}
-----------------
someone get back to me please

Thanks
 
Ranch Hand
Posts: 1087
Oracle Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by sandya patel:

Integer Content_len = request.getContentLength();

Integer Server_port = request.getServerPort();



int Content_len = request.getContentLength();

int Server_port = request.getServerPort();
 
sandya patel
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
nope that doesn't work. I am getting error "Incompatible type for declaration. Can't convert int to java.lang.Integer.
Integer Content_len = request.getContentLength()
;"

I believe something is wrong in import.java.lang or something.
 
sandya patel
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
when I compiled it, i got 0 errors. but when I upload it to tomcat and checked it, i am getting following error


"javax.servlet.ServletException: Wrapper cannot find servlet class Cgi or a class it depends on"

"java.lang.ClassNotFoundException: Cgi"
 
Shailesh Chandra
Ranch Hand
Posts: 1087
Oracle Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
[Posted before above Post]

Originally posted by sandya patel:
Integer Content_len = request.getContentLength();


I am wodering if still you have above line in your code, remember return type of request.getContentLength() is int and you are trying to hold it in an Integer variable.

please check same, also I would recommend you refer servlet documention.

Nearest way to servlet documentaion is, go to Ben's signature
[ April 24, 2005: Message edited by: Shailesh Chandra ]
 
sandya patel
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
oh ok i will this out. also one more clarification.
for every java, we need to have a web.xml fiel right?
so if you are implementing different .java files in same directory, then do we need to create web.xml file for each .java fiel or can just put some mapping in the same web.xml file and then use it??

can we write like this??
<servlet-name>Hello</servlet-name>
<servlet-class>Hello</servlet-class>
<servlet-name>Cgi</servlet-name>
<servlet-class>Cgi</servlet-class>


or do we need to create different web.xml file each time??
 
Shailesh Chandra
Ranch Hand
Posts: 1087
Oracle Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Originally posted by sandya patel:
for every java, we need to have a web.xml fiel right?






I am not sure what you mean by this.
for every web application we need only one web.xml,no matter how many servlet you have in your application .



can we write like this??
<servlet-name>Hello</servlet-name>
<servlet-class>Hello</servlet-class>
<servlet-name>Cgi</servlet-name>
<servlet-class>Cgi</servlet-class>






a little bt modification is required





or do we need to create different web.xml file each time??



you need only one web.xml file

Shailesh
[ April 25, 2005: Message edited by: Shailesh Chandra ]
 
sandya patel
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I changed interger to int. then also, I am getting the same errors when uploaded in Tomcat

"javax.servlet.ServletException: Wrapper cannot find servlet class Cgi or a class it depends on"

"java.lang.ClassNotFoundException: Cgi"

what should be changed now??
 
Shailesh Chandra
Ranch Hand
Posts: 1087
Oracle Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
can you put stacktrace of exception !! because you code is ok if you replaced integer to int, however for my curiosity I tested in on tomacat with JDK 1.5.

I didn't get any error with with Integer because jdk1.5 has automatic conversion facility from primitive values to their wrapper class

Shailesh
[ April 25, 2005: Message edited by: Shailesh Chandra ]
 
sandya patel
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi
what do you mean by "stacktrace of exception !! ". sorry i am novice to java. so i dont know much details. by the way my server is Apache Tomcat/4.1.27. when i deployed in server, it is showing TRUE under "running" column but when i am testing in html page, outputs are not coming and the errors i posted before are coming. i dont know where is wrong??
 
Shailesh Chandra
Ranch Hand
Posts: 1087
Oracle Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
you need to put complete code in a try block then catch the exception in catch block where you can print stacktrace like

try
{
//your code
}
catch(Exception e)
{
e.printStackTrace(); // you will see this on tomcat console

}
make sure that you are compiling correct code and placing in in tomacat



Shailesh
[ April 25, 2005: Message edited by: Shailesh Chandra ]
 
sandya patel
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
HI Shailesh
I am getting these errors after uploding to tomcat and when test the html file. do i need to create jsp file also??is there any way i can chat with you in Yahoo!messeger??

HTTP Status 500 javax.servlet.ServletException: Wrapper cannot find servlet class Cgi or a class it depends on.
java.lang.ClassNotFoundException: Cgi
 
Shailesh Chandra
Ranch Hand
Posts: 1087
Oracle Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by sandya patel:
HI Shailesh
I am getting these errors after uploding to tomcat and when test the html file. do i need to create jsp file also??is there any way i can chat with you in Yahoo!messeger??

HTTP Status 500 javax.servlet.ServletException: Wrapper cannot find servlet class Cgi or a class it depends on.
java.lang.ClassNotFoundException: Cgi



still you can check the stack trace of application in a way I told,
I dont find any problem with servlet code at my machine,possible error can be you are not placing right file in tomcat or there is some problem with your web.xml. regarding YM ...well it will loose the purpose of Javarach, at YM only I would be there but here in JR you will find great brains to help like Bear,Ben Souther they are always available,however I have sent you my YM id in a PM you can add me I am online

I also want to add Ben,adeel and some other one in my YM list but I think that would violate purpose of JR.



Shailesh
[ April 25, 2005: Message edited by: Shailesh Chandra ]
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

HTTP Status 500 javax.servlet.ServletException: Wrapper cannot find servlet class Cgi or a class it depends on




Do you have a class named Cgi?
If so, is it in a package and where is the class file?



BTW: I agree with Shailesh. Moving the conversation to a private message platform and solving it there would make this whole thread useless to someone trying to solve the same problem weeks, months, or years from now.
[ April 25, 2005: Message edited by: Ben Souther ]
 
sandya patel
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Do you have a class named Cgi?
If so, is it in a package and where is the class file?



BTW: I agree with Shailesh. Moving the conversation to a private message platform and solving it there would make this whole thread useless to someone trying to solve the same problem weeks, months, or years from now.
---------------------------------------------------------------------
HI Ben
yes I do have class named Cgi.class. it is in WEB_INF-->classes--->Cgi.class
sorry, i dont want to voilate the rules or whatever. llet me know where my code went wrong.
 
Shailesh Chandra
Ranch Hand
Posts: 1087
Oracle Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I would like to see your web.xml

Shailesh
 
sandya patel
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have two java file in sample application.thats why I included two files "Hi World" and "Cgi".


<?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></display-name>
<servlet>
<servlet-name>Hi World</servlet-name>
<servlet-class>Hi World</servlet-class>
</servlet>
<servlet>
<servlet-name>Cgi</servlet-name>
<servlet-class>Cgi</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Hi World</servlet-name>
<url-pattern>/Hi World</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Cgi</servlet-name>
<url-pattern>/Cgi</url-pattern>
</servlet-mapping>
</web-app>
 
Shailesh Chandra
Ranch Hand
Posts: 1087
Oracle Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
does your hi world servlet work ??? I dont think so , anyway this is out of your problem's conext.

Entries for Cgi servlet is ok in your web.xml
can you put full path of your Cgi.class like c:\tomcat\......
and what is your application name ,also provide URL your invoking on browser.

Shailesh
 
sandya patel
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
does your hi world servlet work ??? I dont think so , anyway this is out of your problem's conext.

Entries for Cgi servlet is ok in your web.xml
can you put full path of your Cgi.class like c:\tomcat\......
and what is your application name ,also provide URL your invoking on browser.

-------------------------------
Yes my HiWorld servlet is working.
path of Cgi class is sample_webapp -->WEB-INF -->classes-->Cgi.class
path of web.xml is sample_webapp -->WEB-INF -->web.xml
application name is Cgi
 
Shailesh Chandra
Ranch Hand
Posts: 1087
Oracle Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
you have defined <servlet-class>Hi World</servlet-class> and there is a space in class name if your servlet hi world is running then that would be not from same web.xml.Are you able to compile a java file with a space in class name

Shailesh
 
sandya patel
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
oh sorry.

i modified it while uploading it, but gave you the old one. i dont have space in "Hi World". Its "HiWorld"
 
Shailesh Chandra
Ranch Hand
Posts: 1087
Oracle Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
we can only assume your environment, and I feel there is some problem in configuration.
Since your HiWorld Servlet is working so on the first instance you can check you code of CGI servlet .

Put the code of CGI servlet in HelloWrold servlet and test ..if you face any error.
If no error is there just compare configuration of both servlet

Shailesh
 
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

Has it been solved? I think there is something wrong with web.xml only.
[ April 26, 2005: Message edited by: Bimal Patel ]
 
sandya patel
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
you are right. i created seperate web.xml for Cgi . then i got the result. thank u very much.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Wait, you don't have 2 web.xml files, do you?
 
Shailesh Chandra
Ranch Hand
Posts: 1087
Oracle Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Ben Souther:
Wait, you don't have 2 web.xml files, do you?



even this made me puzzled sandya is having two different application for two servlet or something is there that is not explained to us.

even no operating system would allow to have two file with same name in one folder.

Shailesh
 
reply
    Bookmark Topic Watch Topic
  • New Topic