File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes jsp vs servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "jsp vs servlet" Watch "jsp vs servlet" New topic

jsp vs servlet

mary sarami

Joined: Feb 11, 2001
Posts: 25
I put together the below jsp to determine which ip address was coming to the site, depending on the ip address a different set of "headers" are included in the page.
How best would I change this into a servlet? Any help would be appreciated. Thank you.

String agent = request.getRemoteAddr();
// this is the default. It is only modified if the
// correct chars are in the Remote Address
// top3 returns content for unknown clients
String incFile = "head3.html";
if ( agent != null ) {
if ( agent.length() < 1 ) {
// return content for Internet Users
incFile = "head1.html";
} else if ( agent.startsWith (("") | | (agent.startsWith("192.103.")))) {
//return content for GNET browsers
incFile = "head2.html";
<%-- dynamically include the file --%>
<jsp:include page="<%= incFile %>" flush="true"></jsp:include>
Frank Carver

Joined: Jan 07, 1999
Posts: 6920
The simplest way to change it into a servlet is to let the JSP container do it for you! Part of the process of compiling JSPs is to generate a servlet, but how you find the servlet it has generated depends on the servlet container.
Why do you need to do this?

Read about me at ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
I agree. Here's the link:
subject: jsp vs servlet
It's not a secret anymore!