Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How to get server variables in JSP

Posted on 2004-04-29
6
Medium Priority
?
7,327 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 7

Accepted Solution

by:
mark-b earned 1000 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 200 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 7

Assisted Solution

by:searlas
searlas earned 800 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

We live in a world of interfaces like the one in the title picture. VBA also allows to use interfaces which offers a lot of possibilities. This article describes how to use interfaces in VBA and how to work around their bugs.
When trying to connect from SSMS v17.x to a SQL Server Integration Services 2016 instance or previous version, you get the error “Connecting to the Integration Services service on the computer failed with the following error: 'The specified service …
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

722 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