Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

how can I get "IP" and how can I upload photo or image files?

  Asked By: Elliott    Date: Oct 26    Category: Java    Views: 753
  

I have following questions in servlet and jsp files:

1- How can I get "IP address" for using in a session status?With which command, I can get it?

2- How can I upload a photo in a file?I don't know what is the command for uploading a
photo.

3- I don't know why the "FORWARD command" doesn't work on my code.I have a problem in forwarding from one file to another file.would you please tell me the complete command?

Would anyone help me?

Share: 

 

3 Answers Found

 
Answer #1    Answered By: Waggoner Fischer     Answered On: Oct 26

there are some methods on "request" that u can use, one of them is "getRemoteAddr()" that returns the IP address  of request!

 
Answer #2    Answered By: Davi Costa     Answered On: Oct 26
 
Answer #3    Answered By: Silk Choco     Answered On: Dec 16

In your JSP, use request.getRemoteAddr(). This returns the IP address of the agent that sent the request as a String.

Also, request.getRemoteHost() will attempt to get the fully qualified host name. If it can't resolve the name however, the IP address will be returned as in getRemoteAddr().

you can use the following code to uplad image or photo :

You can set the image path as a session attribute once you have uploaded and inserted the path to the database:

session.setAttribute("imagePath", imagePath);

<HTML>
<BODY>
<img src="<%= session.getAttribute("imagePath") %>" />
</BODY>
</HTML>


OR use the following code :

Why you do not try to use session.setAttribute("myImage", image)?

Fetch the client ip address by using the code :

request.getHeader("VIA") --> Gateway
request.getHeader("X-FORWARDED-FOR")--> IPaddress

If forward command not working properly means, try to find out the errors what you have did . after fixing it, you can use forward command .

if you want to get your external ip address by using code , use http://www.ip-details.com/ .

 




Tagged: