WEB基础:几个和路径有关的方法
来源:互联网 发布:税务软件安装 编辑:程序博客网 时间:2024/06/04 19:38
在编写JSP/Servlet应用时常常需要从传入的链接中提取一些信息。HttpServletRequest提供了多个方法,这些方法之间容易混淆。总结并举例如下,希望能对大家有所帮助。
举例:
http://localhost:7001/myservlet/somepath/test?someparam=somevalue
request.getPathInfo():返回/somepath/test
request.getRequestURL():返回http://localhost:7001/myservlet/somepath/test
request.getRequestURI():返回/myservlet/somepath/test
request.getServletPath():返回/myservlet
request.getQueryString():返回someparam=somevalue
另外:
给出一个获取系统路径的JSP页:
<%@page
language="java"
contentType="text/html;charset=gb2312"
%>
<%@page import="java.util.*"%>
<%@page import="java.io.*"%>
<%@page import="javax.servlet.http.*"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>
</head>
<%
String sysypath=application.getRealPath("");
ServletContext servletContext = config.getServletContext();
String rootPath = servletContext.getRealPath("/");
String sys=System.getProperty("user.dir");
String ddd=(String)request.getRequestURL().toString();
String uri = request.getRequestURI();
%>
<body>
<div align="center">
<p>系统路径 <%=sysypath%> </p>
<p>系统路径 <%=rootPath%> </p>
<p>sys<%=sys%> </p>
<p>url<%=ddd%> </p>
<p>uri<%=uri%> </p>
</div>
</body>
</html>
实践使你学习的更快!
- WEB基础:几个和路径有关的方法
- servlet中的几个路径有关的方法
- servlet中的几个路径有关的方法
- servlet中的几个路径有关的方法
- servlet中的几个路径有关的方法
- 记录几个和时间有关的方法
- UIImage有关的几个方法
- 有关字符串的几个方法
- 有关UIView、subview的几个基础知识点
- web.xml中有关路径的问题
- WEB-INF有关的目录路径总结
- c# 有关字符串转换的几个方法
- 有关view加载涉及到的几个方法
- 有关main方法的几个小知识点
- php几个常用预定义变量,有关路径的
- Android 有关文件路径的常用方法
- Java web 中几个常用的获取项目路径的方法
- 和编译有关的几个方面
- bsp
- ASP.NET 2.0中将 GridView 导出到 Excel 文件中
- Linux网络服务软件安装备忘录
- 一些SQL Server的应用实例
- sql 生成类
- WEB基础:几个和路径有关的方法
- 将字串 String 转换成数字类型
- project server 2003
- 从 2.4 到 2.6:Linux 内核可装载模块机制的改变对设备驱动的影响
- Swing程序设计2
- 如何将弹出窗提交到自身?
- 重做雷电kevin lynx版---真正为了游戏,而不是练习程序
- jar的基本操作
- 报表工具之JasperReports+iReport(4)