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 9149373
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T11:28:05+00:00 2026-06-17T11:28:05+00:00

I’m currently developing a web site using servlets & spring framework. As usual it

  • 0

I’m currently developing a web site using servlets & spring framework. As usual it contains lots of files (jsp, js, css, images, various resources etc).
I’m trying to avoid writing any hardcoded path, or domain in any file …

For example as you may know when a request is handled you ‘forward’ it to a jsp page (it’s path probably will be hardcoded). Other examples are imports images/css/js etc in jsp files …

Is there any general way (or tools) to avoid hardcoded paths/urls so any refactorings won’t cause troubles?

EDIT
I use netbeans 7.1.2 … Unfortunately netbeans only helps with pure java code. When working with jsp files things are limited, and if you add custom tag files and Jsp 2.0 EL is like programming in console mode :p

  • 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-17T11:28:06+00:00Added an answer on June 17, 2026 at 11:28 am

    Actually I just came up with an idea. Since netbeans does analysis and shows dependencies on java code, maybe it’s better to handle all paths & domains as java variables.

    I’ve created a package on my project named FileResolver and inside I have one class for each file type on my project (eg one class for Jsp files, one for Css files etc). Inside those files I’ll record & hardcode all paths of all files in public static final String variables. Sample:

    public class Jsps {
    
        public class layouts{
            public static final String main =       "layouts/main.jsp";
        }
    
        public class pages{
            public static final String error =      "pages/error.jsp";
            public static final String login =      "pages/login.jsp";
            public static final String register =   "pages/register.jsp";
        }
        ...
    }
    

    All over my project I should use the variables instead of paths. Then anytime I refactor a file, I’ll have only one file to change is the mapping value in those variables …
    And if somethime I need to change the variable, netbeans will refactor all of them in the project at once …
    I think this will work just fine since I keep my project clean from file paths and the only thing I have to worry about is the mapping in that file of the variables to appropriate file paths.

    EDIT
    I’ll write a simple parser to create those java files instead of writting by hand for all files … I’ll update when I finish it


    UPDATE
    Here is my FileResolverGenerator

    public class FileResolverGenerator {
    
        private static final String newFilePath = "C:/Users/Foo/Desktop/Jsps.java";
        private static final String scanRootFolder = "C:/Users/Foo/Desktop/myProject/web/WEB-INF/jsp";
    
        private static final String varValueReplaceSource = "C:/Users/Foo/Desktop/myProject/web/WEB-INF/jsp/";
        private static final String varValueReplaceTarget = "";
    
        private static final boolean valueAlign = true;
        private static final int varNameSpaces = 15;
    
    
        public static void main(String[] args){
            try {
                // Create file and a writer
                File f = new File(newFilePath);
                f.createNewFile();
                bw = new BufferedWriter( new FileWriter(f) );
                // Execute
                filesParser( new File(scanRootFolder) );
                // 'Burn' file
                bw.close();
            } catch (FileNotFoundException ex) {
                Logger.getLogger(ResolverGenerator.class.getName()).log(Level.SEVERE, null, ex);
            } catch (IOException ex) {
                Logger.getLogger(ResolverGenerator.class.getName()).log(Level.SEVERE, null, ex);
            }
    
        }
    
        // ================================================================================================ //
        // ============================================= WORK ============================================= //
        // ================================================================================================ //
    
        private static void filesParser(File rootFolder) throws FileNotFoundException, IOException{
    
            folderIn(rootFolder);
            // Files first
            if(!rootFolder.exists()) throw new FileNotFoundException();
            for(File f : rootFolder.listFiles()){
                if(f==null){ return; }
                if(f.isDirectory()){ continue; }
                else if(f.isFile()){ writeFileVariable(f); }
            }
            // Folders next
            for(File f : rootFolder.listFiles()){
                if(f==null){ return; }
                if(f.isDirectory()){ filesParser(f); }
                else if(f.isFile()){ continue; }
            }
            folderOut(rootFolder);
        }
    
    
        // ================================================================================================ //
        // ============================================ PRINTS ============================================ //
        // ================================================================================================ //
        private static BufferedWriter bw;
        private static int tabCount = 0;
    
    
        private static void folderIn(File f) throws IOException{
            bw.append("\n\n");
            for(int i=0; i<tabCount; i++)
                bw.append("\t");
            bw.append("public class "+f.getName()+"{\n");
            tabCount++;
        }
    
        private static void folderOut(File f) throws IOException{
            tabCount--;
            for(int i=0; i<tabCount; i++)
                bw.append("\t");
            bw.append("}\n");
        }
    
        private static void writeFileVariable(File f) throws IOException{
            String varName = f.getName().split("\\.")[0].replaceAll("-", "");
            String varValue = f.getPath().replaceAll("\\\\","/")
               .replace(varValueReplaceSource.replaceAll("\\\\","/"),varValueReplaceTarget.replaceAll("\\\\","/"));
    
            for(int i=0; i<tabCount; i++)
                bw.append("\t");
            bw.append("public static final String "+varName+" = ");
            if(valueAlign){
                for(int i=0; i<varNameSpaces-varName.length(); i++) bw.append(" ");
                bw.append("\t"); }
            bw.append("\""+varValue+"\";\n");
        }
    
    
    }
    

    Just to be specific … This scans all files under “/WEB-INF/jsp/” and creates a java file having all jsp files ‘registered’ to public static final String variables with each path … The idea is to use the generated java file as reference for all jsps are in project … always use these variables instead of hardcoded paths ..
    This has nothing to do with the project or any project. It’s just a tool which saves you
    time, instead of doing this by hand for every file in the project.

    I also created another class ResolverConsistencyChecker, which takes all variables and checks if the filepath is correct (file exists) … since we didn’t made any changes to filenames and filepaths all tests are passed.
    This method should run when testing project for ‘errors’

    public class ResolverConsistencyChecker {
    
        private static Class checkClass = Jsps.class;
        private static String fullPathPrefix = "C:/Users/Foo/Desktop/myProject/web/WEB-INF/jsp/";
    
    
        public static void main(String[] args){
            try {
                filesChecker( checkClass );
                System.out.println( "Tests passed. All files locations are valid" );
            } catch (FileNotFoundException ex) {
                Logger.getLogger(ResolverConsistencyChecker.class.getName()).log(Level.SEVERE, null, ex);
            } catch (IOException ex) {
                Logger.getLogger(ResolverConsistencyChecker.class.getName()).log(Level.SEVERE, null, ex);
            }
    
        }
    
        // ================================================================================================ //
        // ============================================= WORK ============================================= //
        // ================================================================================================ //
    
        private static void filesChecker(Class rootClass) throws FileNotFoundException, IOException{
    
            // Check file paths in current class depth
            for(Field f : rootClass.getFields()){
                try {
                    String fullFilePath = fullPathPrefix+f.get(f.getName()).toString();
                    File file = new File( fullFilePath );
                    if( !file.exists() )
                        throw new FileNotFoundException("Variable: '"+f.getName()+"'\nFile "+fullFilePath);
                } catch (IllegalArgumentException ex) {
                    Logger.getLogger(ResolverConsistencyChecker.class.getName()).log(Level.SEVERE, null, ex);
                } catch (IllegalAccessException ex) {
                    Logger.getLogger(ResolverConsistencyChecker.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
            // Check for embedded classes
            for(Class c : rootClass.getClasses()){
                filesChecker(c);
            }
        }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I have thousands of HTML files to process using Groovy/Java and I need to
Let's say I'm outputting a post title and in our database, it's Hello Y&#8217;all
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am using JSon response to parse title,date content and thumbnail images and place
I want use html5's new tag to play a wav file (currently only supported

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.