• 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

How to find out cgi variables in java?

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi all,
i would like find out cgi variables(clients IPADDRESS,client browser).
how ?

i tried like this

InetAddress localaddr = InetAddress.getLocalHost();
System.out.println ("ip: " + localaddr.getHostAddress());

is my above is correct to get the clients ipaddress?if yes can anyone tell me hwo to find out client browser.
In jsp we can get like below request.getContentType();
but in java i dont have any idea?

Any help will be greatly appreicated.
 
sohail khan
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
any help??
 
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
guess what, the request in a JSP is nothing more or less than an HttpServletRequest.
You will have the same available in a servlet.

Servlets and JSPs ARE Java in case you didn't know.

Of course outside the context of servlets and JSPs living in a servlet/JSP container you won't have any of that.

The code you mention will more likely give you your own ip address, how in heck do you expect it to return the remote address you're talking to if you ask for the local address???

If you're building your own socket communication, Socket has methods to return the ip address and/or hostname of the remote machine.
Socket is of course a lowlevel connection that knows no highlevel protocols so you'll have to glean the request parameters from the inputstream yourself by parsing the request.
 
sohail khan
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,

>> the request in a JSP is nothing more or less than an HttpServletRequest.
You will have the same available in a servlet.

ok fine.i agree.

so my question is how abt in java getting the ipaddress,browser.

which method i should use??


thanks a million.
 
Jeroen Wenting
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Again, are you using Servlet/JSP or no?
If no, what ARE you using?
And if so, check the API docs...
Browser information is usually sent as an HTTP header (user-agent or something like that) which you can get from your request object.
IP address ditto can bet gotten from the request.
 
sohail khan
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,
i am not using jsp/servlet.
i am using java .
 
Jeroen Wenting
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In that case you need to work with the raw data you get from the network.
I assume you do have that data in some form?
Or do you expect us to write you a complete webserver from scratch?
 
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm moving this to the Sockets and Internet Protocols forum, where I'd guess might be the best place for the topic...
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Having just done a web server from scratch I can say it's really fun. When your server accepts a client request to connect and starts reading it can read headers as one line at a time. When you get a blank line there are no more headers. Most of the stuff you are looking for will be in the headers.

Now the exact format of the headers is a bit tricky. Google for "HTTP header definition" and see what you find. The W3C site has the definitive standard but it's a bit hard to read and short on examples.

Here are some of the comments from my server - from a bunch of different methods. Code available on request, but you'll learn a lot more figuring it out yourself.
 
I suggest huckleberry pie. But the only thing on the gluten free menu is this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic