转自:http://hi.baidu.com/atomicface/blog/item/de62ac10c099c8cea6ef3f5b.html
servlet里经常会用到一些GET方法,容易弄混,把它们记在这儿了。
servletContext.getContextPath()=
servletContext.getRealPath("/")=F:\ess-branch\web\
servletContext.getRealPath("")=F:\ess-branch\web
servletContext.getContextPath()=
servletContext.getServerInfo()=Apache Tomcat/6.0.18
servletContext.getResource("/")=jndi:/localhost/
httpServletRequest.getContextPath()=
httpServletRequest.getLocalAddr()=127.0.0.1
httpServletRequest.getLocalName()=localhost
httpServletRequest.getLocalPort()=8090
httpServletRequest.getPathInfo()=null
httpServletRequest.getPathTranslated()=null
httpServletRequest.getProtocol()=HTTP/1.1
httpServletRequest.getQueryString()=null
httpServletRequest.getRealPath("")已过时=F:\ess-branch\web
httpServletRequest.getRemoteAddr()=127.0.0.1
httpServletRequest.getRemoteHost()=127.0.0.1
httpServletRequest.getRemotePort()=3288
httpServletRequest.getRemoteUser()=null
httpServletRequest.getRequestURI()=/support/indexinfo/uploadPicture.htm
httpServletRequest.getRequestURL()=http://localhost:8090/support/indexinfo/uploadPicture.htm
httpServletRequest.getScheme()=http
httpServletRequest.getServerName()=localhost
httpServletRequest.getServerPort()=8090
httpServletRequest.getServletPath()=/support/indexinfo/uploadPicture.htm
httpServletRequest.getUserPrincipal()=null
ServletContext servletContext = ActionContext.getServletContext();
HttpServletRequest httpServletRequest = ActionContext.getRequest();
if (servletContext == null) {
System.out.println("servletContext is null");
}
if (httpServletRequest == null) {
System.out.println("httpServletRequest is null");
}
System.out.println("servletContext.getContextPath()="
+ servletContext.getContextPath());
System.out.println("servletContext.getRealPath(\"/\")="
+ servletContext.getRealPath("/"));
System.out.println("servletContext.getRealPath(\"\")="
+ servletContext.getRealPath(""));
System.out.println("servletContext.getContextPath()="
+ servletContext.getContextPath());
System.out.println("servletContext.getServerInfo()="
+ servletContext.getServerInfo());
try {
System.out.println("servletContext.getResource(\"/\")="
+ servletContext.getResource("/"));
}
catch (MalformedURLException e) {
e.printStackTrace();
}
// httpServletRequest
System.out.println("httpServletRequest.getContextPath()="
+ httpServletRequest.getContextPath());
System.out.println("httpServletRequest.getLocalAddr()="
+ httpServletRequest.getLocalAddr());
System.out.println("httpServletRequest.getLocalName()="
+ httpServletRequest.getLocalName());
System.out.println("httpServletRequest.getLocalPort()="
+ httpServletRequest.getLocalPort());
System.out.println("httpServletRequest.getPathInfo()="
+ httpServletRequest.getPathInfo());
System.out.println("httpServletRequest.getPathTranslated()="
+ httpServletRequest.getPathTranslated());
System.out.println("httpServletRequest.getProtocol()="
+ httpServletRequest.getProtocol());
System.out.println("httpServletRequest.getQueryString()="
+ httpServletRequest.getQueryString());
System.out.println("httpServletRequest.getRealPath(\"\")已过时="
+ httpServletRequest.getRealPath(""));
System.out.println("httpServletRequest.getRemoteAddr()="
+ httpServletRequest.getRemoteAddr());
System.out.println("httpServletRequest.getRemoteHost()="
+ httpServletRequest.getRemoteHost());
System.out.println("httpServletRequest.getRemotePort()="
+ httpServletRequest.getRemotePort());
System.out.println("httpServletRequest.getRemoteUser()="
+ httpServletRequest.getRemoteUser());
System.out.println("httpServletRequest.getRequestURI()="
+ httpServletRequest.getRequestURI());
System.out.println("httpServletRequest.getRequestURL()="
+ httpServletRequest.getRequestURL());
System.out.println("httpServletRequest.getScheme()="
+ httpServletRequest.getScheme());
System.out.println("httpServletRequest.getServerName()="
+ httpServletRequest.getServerName());
System.out.println("httpServletRequest.getServerPort()="
+ httpServletRequest.getServerPort());
System.out.println("httpServletRequest.getServletPath()="
+ httpServletRequest.getServletPath());
System.out.println("httpServletRequest.getUserPrincipal()="
+ httpServletRequest.getUserPrincipal());
servlet里经常会用到一些GET方法,容易弄混,把它们记在这儿了。
servletContext.getContextPath()=
servletContext.getRealPath("/")=F:\ess-branch\web\
servletContext.getRealPath("")=F:\ess-branch\web
servletContext.getContextPath()=
servletContext.getServerInfo()=Apache Tomcat/6.0.18
servletContext.getResource("/")=jndi:/localhost/
httpServletRequest.getContextPath()=
httpServletRequest.getLocalAddr()=127.0.0.1
httpServletRequest.getLocalName()=localhost
httpServletRequest.getLocalPort()=8090
httpServletRequest.getPathInfo()=null
httpServletRequest.getPathTranslated()=null
httpServletRequest.getProtocol()=HTTP/1.1
httpServletRequest.getQueryString()=null
httpServletRequest.getRealPath("")已过时=F:\ess-branch\web
httpServletRequest.getRemoteAddr()=127.0.0.1
httpServletRequest.getRemoteHost()=127.0.0.1
httpServletRequest.getRemotePort()=3288
httpServletRequest.getRemoteUser()=null
httpServletRequest.getRequestURI()=/support/indexinfo/uploadPicture.htm
httpServletRequest.getRequestURL()=http://localhost:8090/support/indexinfo/uploadPicture.htm
httpServletRequest.getScheme()=http
httpServletRequest.getServerName()=localhost
httpServletRequest.getServerPort()=8090
httpServletRequest.getServletPath()=/support/indexinfo/uploadPicture.htm
httpServletRequest.getUserPrincipal()=null
ServletContext servletContext = ActionContext.getServletContext();
HttpServletRequest httpServletRequest = ActionContext.getRequest();
if (servletContext == null) {
System.out.println("servletContext is null");
}
if (httpServletRequest == null) {
System.out.println("httpServletRequest is null");
}
System.out.println("servletContext.getContextPath()="
+ servletContext.getContextPath());
System.out.println("servletContext.getRealPath(\"/\")="
+ servletContext.getRealPath("/"));
System.out.println("servletContext.getRealPath(\"\")="
+ servletContext.getRealPath(""));
System.out.println("servletContext.getContextPath()="
+ servletContext.getContextPath());
System.out.println("servletContext.getServerInfo()="
+ servletContext.getServerInfo());
try {
System.out.println("servletContext.getResource(\"/\")="
+ servletContext.getResource("/"));
}
catch (MalformedURLException e) {
e.printStackTrace();
}
// httpServletRequest
System.out.println("httpServletRequest.getContextPath()="
+ httpServletRequest.getContextPath());
System.out.println("httpServletRequest.getLocalAddr()="
+ httpServletRequest.getLocalAddr());
System.out.println("httpServletRequest.getLocalName()="
+ httpServletRequest.getLocalName());
System.out.println("httpServletRequest.getLocalPort()="
+ httpServletRequest.getLocalPort());
System.out.println("httpServletRequest.getPathInfo()="
+ httpServletRequest.getPathInfo());
System.out.println("httpServletRequest.getPathTranslated()="
+ httpServletRequest.getPathTranslated());
System.out.println("httpServletRequest.getProtocol()="
+ httpServletRequest.getProtocol());
System.out.println("httpServletRequest.getQueryString()="
+ httpServletRequest.getQueryString());
System.out.println("httpServletRequest.getRealPath(\"\")已过时="
+ httpServletRequest.getRealPath(""));
System.out.println("httpServletRequest.getRemoteAddr()="
+ httpServletRequest.getRemoteAddr());
System.out.println("httpServletRequest.getRemoteHost()="
+ httpServletRequest.getRemoteHost());
System.out.println("httpServletRequest.getRemotePort()="
+ httpServletRequest.getRemotePort());
System.out.println("httpServletRequest.getRemoteUser()="
+ httpServletRequest.getRemoteUser());
System.out.println("httpServletRequest.getRequestURI()="
+ httpServletRequest.getRequestURI());
System.out.println("httpServletRequest.getRequestURL()="
+ httpServletRequest.getRequestURL());
System.out.println("httpServletRequest.getScheme()="
+ httpServletRequest.getScheme());
System.out.println("httpServletRequest.getServerName()="
+ httpServletRequest.getServerName());
System.out.println("httpServletRequest.getServerPort()="
+ httpServletRequest.getServerPort());
System.out.println("httpServletRequest.getServletPath()="
+ httpServletRequest.getServletPath());
System.out.println("httpServletRequest.getUserPrincipal()="
+ httpServletRequest.getUserPrincipal());
发表评论
-
javamail 常见问题
2010-03-16 22:24 2308一般问题 问. 什么是 JavaMail API? 答:J ... -
tomcat性能优化
2010-01-29 13:49 14226关键字: tomcat性能优化 1.精简Tomcat和配置文 ... -
j2ee接口
2009-07-17 11:38 1180j2ee一般只提供一个接口,实现类由容器实现,如tomcat, ... -
RequestDispatcher接口的简述
2009-07-17 11:34 1966RequestDispatcher接口的概述: public ... -
HttpServlet抽象类的简述
2009-07-17 11:34 1124HttpServlet类的简述:public abstract ... -
ServletContext接口的简述
2009-07-17 11:33 943ServletContext接口的简述:public inte ... -
ServletConfig接口的简述
2009-07-17 11:31 979转自:http://www.cnblogs.com/johnn ... -
Servlet API——GenericServlet类的简述
2009-07-17 11:16 1043转自:http://www.cnblogs.com/j ... -
javax.servlet
2009-07-17 10:58 951转自:http://www.cnblogs.com/johnn ... -
javax.servlet.http.Cookie翻译
2009-06-25 18:03 1405转自:http://lavasoft.blog.51cto.c ... -
若干问题解决方案
2008-12-11 18:53 957就客户目前的需求来看 ... -
配置Apache2.2负载平衡+Tomcat6集群(转贴)
2008-12-11 18:38 2471Apache2.2负载平衡+Tomcat6集群 ... -
jar文件修改
2008-12-09 17:18 1368jar文件修改 1.eclipse里面新建一个java工程 2 ...
相关推荐
在Java Web开发中,`servlet-api.jar`和`jsp-api.jar`是非常关键的库文件,它们包含了Servlet和JSP(JavaServer Pages)的核心API,是每个Java Web开发者必备的基础工具。这两个jar包通常由Java EE(Enterprise ...
当服务器不再需要 Servlet, 或重新装入 Servlet 的新实例时,服务器会调用 Servlet 的 destroy() 方法。 3. Java Servlet API Java Servlet 开发工具(JSDK)提供了多个软件包,在编写 Servlet 时需要用到...
在实际开发中,除了Servlet,我们还会用到JSP,这是一种视图技术,允许开发者在HTML中嵌入Java代码,简化了动态页面的开发。Servlet和JSP常常结合使用,Servlet负责业务逻辑处理,JSP负责呈现视图。 总之,"一个...
例如,我们可以创建名为`HelloWorldServlet`的类,并重写`doGet`方法来处理HTTP GET请求: ```java import javax.servlet.*; import javax.servlet.http.*; import java.io.*; public class HelloWorldServlet ...
当服务器关闭或Servlet不再需要时,会执行`destroy()`方法进行清理工作。 2. HTTP请求响应流程: 用户在浏览器中输入URL,这个请求会被发送到服务器。Servlet容器(如Tomcat)接收到请求后,根据请求的URL找到对应...
当第一次请求Servlet时,容器(如Tomcat)会加载Servlet类并调用`init()`方法进行初始化,然后每次请求都会调用`service()`方法处理,最后在应用关闭或容器认为Servlet不再需要时调用`destroy()`方法。 2. **HTTP...
当客户端发起请求时,Servlet容器(如Tomcat)会加载并实例化Servlet,调用其`service()`方法来处理请求,然后将响应返回给客户端。开发者需要继承`javax.servlet.http.HttpServlet`类并重写对应的方法,例如`doGet...
在JSP中,通常会使用表单元素来获取用户输入,如`<form>`标签,然后通过POST或GET方法提交到对应的Servlet。Servlet通过`HttpServletRequest`对象获取这些参数,进行验证和处理。对于数据库操作,Servlet会使用Java ...
在实现上述功能时,会用到Servlet API中的各种类和接口,如`HttpServlet`、`HttpServletRequest`和`HttpServletResponse`。`HttpServlet`是所有Servlet的基类,提供处理HTTP请求的基本方法。`HttpServletRequest`...
1. **HTTP协议**:理解HTTP请求和响应的工作原理,包括GET和POST方法,以及如何在Servlet中处理这些请求。 2. **JSP内置对象**:如request、response、session、application等,它们在传递数据和管理会话中起着关键...
在JDBC中,我们通常会用到DriverManager类来注册数据库驱动,Connection对象来建立与数据库的连接,Statement或PreparedStatement对象来执行SQL语句,而ResultSet对象则用于存储查询结果。 【Servlet】是Java ...
在Servlet的`init()`方法中,我们可以加载数据库驱动,建立连接池,并获取数据库连接。例如: ```java import java.sql.Connection; import java.sql.DriverManager; import javax.sql.DataSource; import org....
在JSP+Servlet架构中,常常会用到MVC(Model-View-Controller)设计模式。在这个项目中,JSP作为视图(View),负责展示数据;Servlet作为控制器(Controller),处理用户请求,调用模型(Model,即业务逻辑和数据...
【Servlet聊天室】是一个基于Java和Servlet技术实现的在线交流平台。Servlet是Java服务器端编程的重要组成部分,主要用于处理HTTP请求并生成动态响应。这个聊天室项目可以帮助我们深入了解Servlet的工作原理以及如何...
在服务阶段,每当有新的请求到达,Servlet容器都会调用`service()`方法,该方法会根据请求类型(GET、POST等)选择合适的`doGet()`或`doPost()`等方法来处理请求。最后,当Servlet不再需要或者Web应用停止时,容器会...
在这个压缩包中,包含了他讲解servlet时用到的源码文件,这些文件可以帮助我们更直观地理解Servlet的工作原理和编程实践。 1. **Servlet的基本概念** Servlet是一个Java类,实现了javax.servlet.Servlet接口或其子...
在代码中会用到Statement对象来执行SQL语句。 7. 配置文件的使用:在Web应用中,通常会利用web.xml文件来配置Servlet。可以指定Servlet名称、类名以及映射的URL模式。示例配置如下: ```xml <servlet> <servlet-...
在Servlet中,`RequestDispatcher`接口的`forward()`方法可以将当前请求转发到另一个资源,而`HttpServletResponse`的`sendRedirect()`方法则会向客户端发送一个重定向响应,让浏览器发起新的HTTP请求。 为了运行这...
在实际开发中,我们还会用到其他与Servlet相关的接口和类,如Servlet、GenericServlet、ServletConfig、Filter等。Servlet接口定义了服务HTTP请求的方法`service()`,而GenericServlet是Servlet的一个抽象基类,提供...
3. **msutil.jar**: 这个JAR文件包含了一些实用工具类,可能包括日期/时间处理、加密、性能监视等功能,这些功能在与SQL Server交互时可能会用到。 为了在Tomcat服务器上运行Servlet并连接到SQL Server 2000,你...