Solved

JSP - how to get filename only from the HTTP header

Posted on 2003-11-07
6
356 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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

In this article, I show you step by step with screenshots to assist you - HOW TO: Deploy and Install the VMware vCenter Server Appliance 6.5 (VCSA 6.5), with some helpful tips along the way.
What is Backup? Backup software creates one or more copies of the data on your digital devices in case your original data is lost or damaged. Different backup solutions protect different kinds of data and different combinations of devices. For e…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

746 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

14 Experts available now in Live!

Get 1:1 Help Now