东东车 2010-07-15 22:57
浏览 231
已采纳

请教一个标签定制的基础问题

DispIP类
[code="java"]package macleo;
import java.io.IOException;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.TagSupport;

public class DispIP extends TagSupport {

/**
 * 
 */
private static final long serialVersionUID = 1L;

public int doStartTag() throws JspException
{
    String ip = pageContext.getRequest().getRemoteAddr();//问题
    try {
        pageContext.getOut().write(ip);
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return super.doStartTag();
}

}[/code]
我查阅了j2ee的api,有点问题不明白,请教各位达人,请指点一下.
1.TagSupport类的定义如下:
[code="java"]/**

  • A base class for defining new tag handlers implementing Tag. *
  • The TagSupport class is a utility class intended to be used as

  • the base class for new tag handlers. The TagSupport class
  • implements the Tag and IterationTag interfaces and adds additional
  • convenience methods including getter methods for the properties in
  • Tag. TagSupport has one static method that is included to
  • facilitate coordination among cooperating tags. *
  • Many tag handlers will extend TagSupport and only redefine a

  • few methods. */

public class TagSupport implements IterationTag, Serializabl[/code]
其中有
[code="java"] // protected fields

/**
 * The PageContext.
 */
protected PageContext pageContext;[/code]

2.PageContext定义如下,是抽象类
[code="java"] *

  • The following methods provide support for forwarding, inclusion
  • and error handling:
  • forward(), include(),
  • and handlePageException(). */

abstract public class PageContext
extends JspContext[/code]

其中,getRequest()方法未实现是abstract的定义如下:
[code="java"]
/**
* The current value of the request object (a ServletRequest).
*
* @return The ServletRequest for this PageContext
*/

abstract public ServletRequest getRequest();[/code]

3.getRemoteAddr方法定义(亦未实现)在interface的ServletRequest中,定义如下:
[code="java"] /**
* Returns the Internet Protocol (IP) address of the client
* or last proxy that sent the request.
* For HTTP servlets, same as the value of the
* CGI variable REMOTE_ADDR.
*
* @return a String containing the
* IP address of the client that sent the request
*
*/

public String getRemoteAddr();
[/code]

***我的问题是:DispIP类中此句,两方法均为实现,何以能编译通过呢????晕,请指点!感谢!
[code="java"]String ip = pageContext.getRequest().getRemoteAddr();//问题[/code]

  • 写回答

2条回答 默认 最新

  • CaiHuajiang 2010-07-16 00:09
    关注

    这两个类由容器具体实现.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
  • ¥30 python代码,帮调试
  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿