servlet如何利用request来获取http请求中的主体信息

servlet如何利用request来获取http请求中的主体信息,第1张

getProtocol():获取请求使用的通信协议,如>

web应用:

EL表达式获取: ${pageContextrequestcontextPath }

EL表达式通过配置初始化参数获取: ${initParamroot }

2 获取servlet的路径:

a requestgetFullName(); 获取到当前servlet的名称

b requestgetContextPath(); 获取整个web应用的名称

c requestsetAttribute("name", (b) + "/servlet/" + (a) ); 作为参数传递给 bjsp

d 在jsp页面通过EL表达式获取: ${name }

      希望能帮助你

java获取根路径有两种方式:

1),在servlet可以用一下方法取得:

requestgetRealPath(“/”) 例如:filepach = requestgetRealPath(“/”) ”//upload//”;

2),不从jsp,或servlet中获取,只从普通java类中获取:

String path =

getClass()getProtectionDomain()getCodeSource()getLocation()getPath();

SAXReader() saxReader = new SAXReader();

if(pathindexOf(“WEB-INF”)>0){

path = pathsubstring(0,pathindexOf(“/WEB-INF/classes”) 16);

// ‘/WEB-INF/classes’为16位

document = saxReaderread(path filename);

}else{

document = saxReaderread(getClass()getResourceAsStream(filename));

}

weblogic tomcat 下都有效

String path =

getClass()getProtectionDomain()getCodeSource()getLocation()getPath();

<!--EndFragment-->

很多朋友都想知道java如何获取当前目录路径?下面就一起来了解一下吧~

1、利用SystemgetProperty()函数获取当前路径:

Systemoutprintln(SystemgetProperty("userdir"));//userdir指定了当前的路径

2、使用File提供的函数获取当前路径:

File directory = new File("");//设定为当前文件夹 try{ Systemoutprintln(directorygetCanonicalPath());//获取标准的路径 Systemoutprintln(directorygetAbsolutePath());//获取绝对路径 }catch(Exceptin e){} FilegetCanonicalPath()和FilegetAbsolutePath()大约只是对于new File("")和new File("")两种路径有所区别。 # 对于getCanonicalPath()函数,“"就表示当前的文件夹,而”“则表示当前文件夹的上一级文件夹 # 对于getAbsolutePath()函数,则不管””、“”,返回当前的路径加上你在new File()时设定的路径 # 至于getPath()函数,得到的只是你在new File()时设定的路径 比如当前的路径为 C:/test : File directory = new File("abc"); directorygetCanonicalPath(); //得到的是C:/test/abc directorygetAbsolutePath(); //得到的是C:/test/abc direcotrygetPath(); //得到的是abc File directory = new File(""); directorygetCanonicalPath(); //得到的是C:/test directorygetAbsolutePath(); //得到的是C:/test/ direcotrygetPath(); //得到的是 File directory = new File(""); directorygetCanonicalPath(); //得到的是C:/ directorygetAbsolutePath(); //得到的是C:/test/ direcotrygetPath(); //得到的是 另外:SystemgetProperty()中的字符串参数如下: SystemgetProperty()参数大全 # javaversion Java Runtime Environment version # javavendor Java Runtime Environment vendor # javavendorurl Java vendor URL # javahome Java installation directory # javavmspecificationversion Java Virtual Machine specification version # javavmspecificationvendor Java Virtual Machine specification vendor # javavmspecificationname Java Virtual Machine specification name # javavmversion Java Virtual Machine implementation version # javavmvendor Java Virtual Machine implementation vendor # javavmname Java Virtual Machine implementation name # javaspecificationversion Java Runtime Environment specification version # javaspecificationvendor Java Runtime Environment specification vendor # javaspecificationname Java Runtime Environment specification name # javaclassversion Java class format version number # javaclasspath Java class path # javalibrarypath List of paths to search when loading libraries # javaiotmpdir Default temp file path # javacompiler Name of JIT compiler to use # javaextdirs Path of extension directory or directories # osname Operating system name # osarch Operating system architecture # osversion Operating system version # fileseparator File separator ("/" on UNIX) # pathseparator Path separator (":" on UNIX) # lineseparator Line separator ("/n" on UNIX) # username User’s account name # userhome User’s home directory # userdir User’s current working directory

JAVA中获取路径 关键字: java中获取路径

1、jsp中取得路径:

以工程名为TEST为例:

(1)得到包含工程名的当前页面全路径:requestgetRequestURI() 结果:/TEST/testjsp (2)得到工程名:requestgetContextPath() 结果:/TEST (3)得到当前页面所在目录下全名称:requestgetServletPath() 结果:如果页面在jsp目录下 /TEST/jsp/testjsp (4)得到页面所在服务器的全路径:applicationgetRealPath("页面jsp") 结果:D:/resin/webapps/TEST/testjsp (5)得到页面所在服务器的绝对路径:absPath=new javaioFile(applicationgetRealPath(requestgetRequestURI()))getParent(); 结果:D:/resin/webapps/TEST

2、在类中取得路径: (1)类的绝对路径:ClassclassgetClass()getResource("/")getPath() 结果:/D:/TEST/WebRoot/WEB-INF/classes/pack/ (2)得到工程的路径:SystemgetProperty("userdir") 结果:D:/TEST

您好,//import语句就不写了,反正现在的IDE这么先进,这难不了大家的

public class GetA000_photoServlet extends >

很多朋友都想了解java如何获取当前项目的路径?下面就一起来了解一下吧~

在jsp和class文件中调用的相对路径不同。

在jsp里,根目录是WebRoot

在class文件中,根目录是WebRoot/WEB-INF/classes 也可以选用SystemgetProperty("userdir")获取工程的绝对路径。

1jsp中取得路径:

以工程名为TEST为例:

(1)得到包含工程名的当前页面全路径:requestgetRequestURI() 结果:/TEST/testjsp (2)得到工程名:requestgetContextPath() 结果:/TEST (3)得到当前页面所在目录下全名称:requestgetServletPath() 结果:如果页面在jsp目录下 /TEST/jsp/testjsp (4)得到页面所在服务器的全路径:applicationgetRealPath("页面jsp") 结果:D: esinwebappsTEST estjsp (5)得到页面所在服务器的绝对路径:absPath=new javaioFile(applicationgetRealPath(requestgetRequestURI()))getParent(); 结果:D: esinwebappsTEST

2在class类中取得路径:

(1)类的绝对路径:ClassclassgetClass()getResource("/")getPath() 结果:/D:/TEST/WebRoot/WEB-INF/classes/pack/ (2)得到工程的路径:SystemgetProperty("userdir") 结果:D:TEST

3在Servlet中取得路径: (1)得到工程目录:requestgetSession()getServletContext()getRealPath("") 参数可具体到包名。 结果:E:TomcatwebappsTEST (2)得到IE地址栏地址:requestgetRequestURL() 结果:>

以上就是关于servlet如何利用request来获取http请求中的主体信息全部的内容,包括:servlet如何利用request来获取http请求中的主体信息、jsp获取发起请求的servlet路径、java如何获得linux下web路径等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/9378002.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-04-27
下一篇2023-04-27

发表评论

登录后才能评论

评论列表(0条)

    保存