Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

JSP - how to get filename only from the HTTP header

Posted on 2003-11-07
6
Medium Priority
?
374 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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

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!

Question has a verified solution.

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

WooCommerce is becoming the most powerful e-commerce plugin for Wordpress. And why not. The platform comprises of numerous core plugins that may come in handy, powerful options to make your website development task much easier.
With so many activities to perform, Exchange administrators are always busy in organizations. If everything, including Exchange Servers, Outlook clients, and Office 365 accounts work without any issues, they can sit and relax. But unfortunately, it…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses

636 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