Use several static directories with JT when the server runs:
http: // localhost: 8282 / one http: // localhost: 8282 / b http: // localhost: 8282 / c A was placed in X / V / A B is placed in Q / Z / B C is placed in P / T / C The following failed:
resourcehanger resource_handler = new resource handler (); Resource_handler.setWelcomeFiles (new string [] {"index.html"}); Resource_handler.setResourceBase (HTML_SITE); ResourceHandler Resources_Handler1 = New ResourceHandler (); Resource_handler1.setWelcomeFiles (new string [] {"index.html"}); Resource_handler1.setResourceBase (HTML_CLIENTZONE_SITE); // Deploy Engine WebAppContext webapp = New WebAppContext (); String diamor = System.getProperty ("user.dir"); Webapp.setResourceBase (getWebAppPath ()); Webapp.setContextPath ("/"); Handler list operators = new handler list (); Handlers.SetHandlers (new handler [] {resource_handler, resource_handler1, webapp, new default handler ()}); Server.setHandler (handler); How do I add more than one static resource directory? Since 6.1.12, it is supported by using ResourceCollection in WebAppContext based resource:
server server = new server (8282); WebAppContext Reference = New WebAppContext (); Context.setContextPath ("/"); ResourceCollection Resource = New Corrections (New String [] {"Project / WebApp / Folder", "/ root / static / Folder / A", "/ root / static / folder / b",}); Context.setBaseResource (resource); Server.setHandler (reference); Server.start (); To open a file later, use the SyntaxText (e.g., WebPass Context), which can be part of an interface definition, such as: / ** * Opens the file using the servlet reference * / Public Default Input Sprint Open (CircaleContent Reference, String Filename) {String F = System.JetProperty (" File Separator ") + File name; Return context.getResourceAsstream (f); } as such:
InputStream = open (context, "filename.txt") ; This will open filename.txt if it exists in one of the given directories, note that instead of leaving the getResourceAsStream exception, null Returning, so it is a good idea to check: public default InputStream throws fileNotFoundException valid (InputStream, string filename) (if == empty In) {New FileNotFoundException (filename); } Return; } Then you can update the open method as follows: Back valid (context.getResourceAsStream (filename), file name);
Comments
Post a Comment