Solved

How to get server variables in JSP

Posted on 2004-04-29
6
7,063 Views
Last Modified: 2010-05-18
Hi,  does anyone know how to get server variables such as

remoteHost
Locale
UserAgent
Referer

using JAVA in-line in JSP?
Thanks in advance..
0
Comment
Question by:rosshind
6 Comments
 
LVL 7

Accepted Solution

by:
mark-b earned 250 total points
ID: 10948785
There is an implicit request object available in JSPs:

request.getHeader( "User-Agent" );
request.getRemoteHost();
request.getHeader( "Referer" );
request.getLocale();

-Mark
0
 
LVL 4

Assisted Solution

by:indigostark
indigostark earned 50 total points
ID: 10948947
Where servletRequest = javax.servlet.http.HttpServletRequest

//Get specific details about the User
String remoteHost = servletRequest.getRemoteHost();
String remoteAddress = servletRequest.getRemoteAddr();
java.util.Locale locale = servletRequest.getLocale();
String country = locale.getDisplayCountry();
String userAgent = servletRequest.getHeader("User-Agent");
String refererr = servletRequest.getHeader("Referer");
String encodings = servletRequest.getHeader("Accept-Encoding");

//check for null values
if(remoteHost==null || remoteHost.equals(""))
remoteHost="Unknown";
            
if(remoteAddress==null || remoteAddress.equals(""))
remoteAddress="Unknown";
            
if(country==null || country.equals(""))
country="Unknown";
            
if(userAgent==null)
userAgent="";
            
if(refererr==null)
refererr="";
0
 

Author Comment

by:rosshind
ID: 10949341
When I try to use teh imlicit variables I get this  error message:

/home/hindrm/jakarta-tomcat-4.1.29/work/Standalone/localhost/_/rmh/ProductDetails_jsp.java:493: cannot resolve symbol
symbol  : variable request
0
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.

 
LVL 7

Assisted Solution

by:searlas
searlas earned 200 total points
ID: 10949399
Have you put this code in a method as so:
<%!
void someMethod() {
  String referer = request.getHeader( "Referer" );
}
%>

If so, you need to change it to:
<%!
void someMethod(HttpServletRequest request) {
  String referer = request.getHeader( "Referer" );
}
%>

and call it with <% someMethod(request); %>


0
 

Author Comment

by:rosshind
ID: 10949423
I think this may be a problem with using thoes implicit variables within a funtion delimited by the <%! and %> tags.

I have the same problem with the "out" implicit variables.

Do you know why this might be?
0
 

Author Comment

by:rosshind
ID: 10949430
Ah I see, you have answered my question there.

Thanks.
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
ajax auto save 15 98
reflection example 3 92
authenticate preemptively soap ui option 3 123
Java Script nested call 3 75
This article lists the top 5 free OST to PST Converter Tools. These tools save a lot of time for users when they want to convert OST to PST after their exchange server is no longer available or some other critical issue with exchange server or impor…
We need a new way to communicate time sensitive or critical info.   The best part of my role at xMatters is visiting our clients all over the world to learn about how they operate their businesses, share insights that xMatters has gleaned across…
This is a video that shows how the OnPage alerts system integrates into ConnectWise, how a trigger is set, how a page is sent via the trigger, and how the SENT, DELIVERED, READ & REPLIED receipts get entered into the internal tab of the ConnectWise …
A company’s greatest vulnerability is their email. CEO fraud, ransomware and spear phishing attacks are the no1 threat to a company’s security. Cybercrime is responsible for the largest loss of money to companies today with losses projected to r…

932 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

10 Experts available now in Live!

Get 1:1 Help Now