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
Solved

JSP - how to get filename only from the HTTP header

Posted on 2003-11-07
6
361 Views
Last Modified: 2008-03-06
hi, i need to extract the filename only from the HTTP header (getRequestURI?) excluding the ".jsp". so if "folder/file.jsp" was the path i need "file" as a variable. this is so i know what page the user is on for setting up menu selected states, etc.

however i can't figure out how to do simple string manipulation in JSP!  (we are purely ASP / VBScript developers here)

thanks!
0
Comment
Question by:equentin
  • 4
  • 2
6 Comments
 
LVL 15

Expert Comment

by:jimmack
ID: 9701261
getServletPath() will tell you the part of the URL that called the servlet.
0
 
LVL 15

Expert Comment

by:jimmack
ID: 9701517
From within a JSP, you can do the following:

<%
String path = request.getServletPath();
String fileNameOnly = path.substring(path.lastIndexOf("/") + 1, path.lastIndexOf("."));
out.println(fileNameOnly);
%>

0
 

Author Comment

by:equentin
ID: 9701759
cool, thanks, but how about a potential folder name?

i suppose i could get the lastIndexOf "/" then backtrack from there to find the next "/" then pull out whatever is in between, or if not found then there is no folder.

any better ideas?

0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
LVL 15

Expert Comment

by:jimmack
ID: 9701814
0
 

Author Comment

by:equentin
ID: 9701821
ok, you've answered this question in my other question!

thanks :)
0
 
LVL 15

Accepted Solution

by:
jimmack earned 200 total points
ID: 9701836
No problem ;-)
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
jersey maven project error 7 142
constructor overloading 2 86
Books that can get me started on JAVA 2 105
jsp insert to database example 2 46
IT certifications are a concrete representation of continual learning on the part of the candidate.  Continual learning is necessary for the long term success of an IT professional, but are IT certifications the right path for you?
Learn how to PXE Boot both BIOS & UEFI machines with DHCP Policies and Custom Vendor Classes
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

861 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