?
Solved

JSP - how to get filename only from the HTTP header

Posted on 2003-11-07
6
Medium Priority
?
369 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
[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
  • 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
Industry Leaders: 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 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 800 total points
ID: 9701836
No problem ;-)
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

What's worse than having your data encrypted by ransomware? Getting attacked by a so-called "wiper," which simply destroys the data and offers you no hope of ever seeing it again.
This month, Experts Exchange’s free Course of the Month is focused on CompTIA IT Fundamentals.
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…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses
Course of the Month13 days, 15 hours left to enroll

801 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