Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8833865
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T08:53:06+00:00 2026-06-14T08:53:06+00:00

help to make such a thing (in the previous answer, I was told that

  • 0

help to make such a thing (in the previous answer, I was told that I was poorly explained, and now try to explain poponyatneee) I have a form, just a form, the code it is:

<form action="searchf" method="Post">
<input type="text" name="text" autofocus >
<input type="submit" value="">
</form>

The user enters into this form different file names, such as: index.txt, hello.html (files with duplicate names not, and basically it will txt files). Next, the servlet takes string that the user enters:

String myName = request.getParameter("text");

Continue program called input files looking for the files in the folder, but the fact is that it is necessary to enter index.html program to find the file in the folder, not just index, here’s help to enter the extension was not necessarily trying to do so :

String myNamee = request.getParameter("text");
String myName = myNamee.replaceFirst("[.][^.]+$", "");

It did not work (I will be glad to any replies

Eric Scot

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T08:53:07+00:00Added an answer on June 14, 2026 at 8:53 am

    If you need to separate the file extension from the filename, you can do something like this:

    String file = request.getParameter("text");
    String fileNoExt, fileExt = "";
    if(file.indexOf(".") == -1) {
       fileNoExt = file;
    else {
       fileNoExt = file.substring(0,file.lastIndexOf("."));
       fileExt  = file.substring(file.lastIndexOf(".")+1);
    }
    

    I recommend that you test this code outside the context of Servlets. Just create a simple Java program with a main method to search a directory for a file and you can forget the user-input and form info. Just hard code some test data to make sure you know how to look through a directory and your code to handle the filenames is working correctly.

    You may find this other stack overflow question helpful for understanding how to serach through a directory for a file.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We're looking at patterns such as MVP that can help make us seperate UI
Who can help me make the following query work... Both tables have the fields
Are there any gems that would help me make a search box like the
I have done extensive client-side validation through the help from jQuery. Now come to
I'm hoping that I can explain this well enough. I have an excel document
1) Custom exceptions can help make your intentions clear. How can this be? The
I want to using Linq to help make a list of movies an actor
first time post here. I was hoping someone could help me make custom SPARQL
Does anyone help me to make the news items stop moving when hover on
Could you help me to make this query faster. My query is workable, but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.