webroot下的文件路径|java如何得到项目的webRoot 路径

1. myeclipse中的webroot中的文件夹是什么时候生成的 怎么来的呢 和数据库有关系吗

建立java web项目时就会产生,主要存放web网页和相关的文件,访问网页时,webroot下的网页文件是Web 应用服务器访问的默认路径。

2. java web 中src路径和webroot路径问题

如果是在项目里,比如你在eclipse里的话那就是用src里的,如果你把项目放到服务器上运行,那就是webroot里的

3. webroot文件夹在哪

xp下 好像安装好了IIS后,就可以看到吧··· 系统盘下面 inetpub文件夹下面吧

4. java如何得到项目的webRoot 路径

使用JAVA后台代码取得WEBROOT物理路径,可以有如下两种方式:1、使用jsP Servlet取得WEB根路径可以用request.getContextPath(),相对路径request.getSession().getServletContext().getRealPath("/"),它们可以使用我们很容易取得根路径。 2、如果使用了spring, 在WEB-INF/web.xml中,创建一个webAppRootKey的param,指定一个值(默认为webapp.root)作为键值,然后通过Listener,或者Filter,或者Servlet执行String webAppRootKey = getServletContext().getRealPath("/"); 并将webAppRootKey对应的webapp.root分别作为Key,Value写到System Properties系统属性中。之后在程序中通过System.getProperty("webapp.root")来获得WebRoot的物理路径。具体示例代码如下:web.xml <?xml version="1.0" encoding="UTF-8"?> <web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"> <context-param> <param-name>webAppRootKey</param-name> <param-value>csc2.root</param-value> </context-param> <listener> <listener-class>test.ApplicationListener</listener-class> </listener> </web-app> ApplicationListener.java package test; import javax.servlet.ServletContextEvent; import org.springframework.web.context.ContextLoaderListener; public class ApplicationListener extends ContextLoaderListener { public void contextDestroyed(ServletContextEvent sce) { // TODO Auto-generated method stub } public void contextInitialized(ServletContextEvent sce) { // TODO Auto-generated method stub String webAppRootKey = sce.getServletContext().getRealPath("/"); System.setProperty("csc2.root" , webAppRootKey); String path =System.getProperty("csc2.root"); System.out.println("sssss:::"+path); } } test.java public class test { public void remve(){ String path =System.getProperty("csc2.root"); System.out.println("result::::::::"+path); } } index.jsp <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> <%@ page import="java.util.*" %> <%@ page import="test.test" %> <% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %> <% test t = new test(); t.remve(); %> <html> </html> 部署程序发布 启动TOMCAT 运行index.jsp 就可以调用JAVA中全局设置的物理路径了(说明这里的JSP 只是调用了TEST.JAVA 的remove方法,不做其他使用。原理解释,TOMCAT启动和读取WEB.XML 监听方式加载SPRING ApplicationListener继承SPRING ContextLoaderListener加载SPRING顺便吧全局路径赋值给csc2.root 描述,这样之后JAVA 代码中就可以使用System.getProperty("csc2.root")调用全路路径了。

5. java web工程 我生成一个EXCEL文件存放到 project/WebRoot/file文件下,在severt中存储、修改的路径怎么写

不知道你到底想要将你的文件话到什么地方,如果你是用tomcat的话,可以扩展org.apache.naming.resources.FileDirContext类(${TOMCAT_HOME}/lib/catalina.jar包下),然后在server.xml中进行配置,这样的话,你可以将你的文件放到任何你想放的地方,也不需要你写servlet(当然了,这只是你不需要做特别处理的情况下)。扩展样例代码:package zhangyw.test.tomcat;import java.io.File;import org.apache.naming.resources.FileDirContext;public class VirtualFileDirContext extends FileDirContext { private String directory = null; public void setDirectory(final String directory) { this.directory = directory; } @Override protected File file(final String name) { File file = super.file(name); if (file != null) { return file; } file = new File(directory, name); return file; }}server.xml中的配置样例<Context docBase="tomcatweb" path="/tomcatweb" reloadable="true" source="org.eclipse.jst.jee.server:tomcatweb"> <Resources className="zhangyw.test.tomcat.VirtualFileDirContext" directory="D:\Books"/></Context>使用样例http://localhost:8080/tomcatweb/php_manual_zh.chm其中,tomcatweb是当前web应用的上下文,php_manual_zh.chm在文件系统中的实际路径为"D:\Books\php_manual_zh.chm"。以上,希望对你有帮助,没有问题的话,请采纳。

6. javaweb webRoot 下的文件怎么访问

启动你的服务器,例如tomcat后直接http://localhost:端口/项目名/index.jsphttp://localhost:端口/项目名/kuang.jsp http://localhost:端口/项目名/css/xxx.css以此类推,就可以了但是这样不能访问WEB-INF目录下的所有东西

7. web中如何获得webroot下文件夹中的文件

webroot 在应用中就是应用根目录,你要在程序中使用就是String path=getServletContext().getRealPath("/");就能拿到WebRoot这个根目录下,下面的你再拼一下

8. java 怎么获取服务器webroot的路径

使用JAVA后台代码取得WEBROOT物理路径,可以有如下两种方式:1、使用JSP Servlet取得WEB根路径可以用request.getContextPath(),相对路径request.getSession().getServletContext().getRealPath("/"),它们可以使用我们很容易取得根路径。 2、如果使用了spring, 在WEB-INF/web.xml中,创建一个webAppRootKey的param,指定一个值(默认为webapp.root)作为键值,然后通过Listener,或者Filter,或者Servlet执行String webAppRootKey = getServletContext().getRealPath("/"); 并将webAppRootKey对应的webapp.root分别作为Key,Value写到System Properties系统属性中。之后在程序中通过System.getProperty("webapp.root")来获得WebRoot的物理路径。具体示例代码如下:web.xml<?xml version="1.0" encoding="UTF-8"?> <web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"> <context-param> <param-name>webAppRootKey</param-name> <param-value>csc2.root</param-value> </context-param> <listener> <listener-class>test.ApplicationListener</listener-class> </listener> </web-app> ApplicationListener.javapackage test; import javax.servlet.ServletContextEvent; import org.springframework.web.context.ContextLoaderListener; public class ApplicationListener extends ContextLoaderListener { public void contextDestroyed(ServletContextEvent sce) { // TODO Auto-generated method stub } public void contextInitialized(ServletContextEvent sce) { // TODO Auto-generated method stub String webAppRootKey = sce.getServletContext().getRealPath("/"); System.setProperty("csc2.root" , webAppRootKey); String path =System.getProperty("csc2.root"); System.out.println("sssss:::"+path); } } test.javapublic class test { public void remve(){ String path =System.getProperty("csc2.root"); System.out.println("result::::::::"+path); } } index.jsp<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> <%@ page import="java.util.*" %> <%@ page import="test.test" %> <% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %> <%test t = new test(); t.remve(); %> <html> </html> 部署程序发布 启动TOMCAT 运行index.jsp 就可以调用JAVA中全局设置的物理路径了(说明这里的JSP 只是调用了TEST.JAVA 的remove方法,不做其他使用。原理解释,TOMCAT启动和读取WEB.XML 监听方式加载SPRING ApplicationListener继承SPRING ContextLoaderListener加载SPRING顺便吧全局路径赋值给csc2.root 描述,这样之后JAVA 代码中就可以使用System.getProperty("csc2.root")调用全路路径了。

9. webroot下的jsp访问路径怎么写

webroot是根目录,访问路径就是jsp所在的服务器地址+项目名称+jsp名例如:http://localhost:8080/项目名/xx.jsp


赞 (0)