servlet中getXXX()方法具体实现渊自何处???

xijianyu 2003-10-07 10:13:41
接口HttpServletRequest中对各种getXXX方法都作了定义,如:
public String getMethod();

简单servlet原码如下:
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
public class Hello extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException
{
String name = request.getParameter("username");
if (name == null)
name = (String)request.getSession().getAttribut("username");

if (name == null) name = "World";

response.setContentType("text/html");

PrintWriter out = response.getWriter();

out.println("Hello " + name + "!");
}


public void doPost(HttpServletRequest request,HttpServletResponse response)
throws IOException
{
doGet(request, response);
}
}
servlet原码中用到了接口HttpServletRequest的一个对象request,并且调用了他的方法request.getParameter("username");但是这些方法getXXX()在哪里实现的呢???
...全文
62 10 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
hj12 2003-10-08
  • 打赏
  • 举报
回复
这样的话问题又回到开始了。jsp的内置对象是什么时候由谁创建的呢?
内置对象是由你的 SERVLET容器创建的,也就是TOMCAT。
youandi79 2003-10-07
  • 打赏
  • 举报
回复
servlet container
xijianyu 2003-10-07
  • 打赏
  • 举报
回复
没有,这里也只是给出了这些方法的定义,HttpServletRequest 中也是。
package javax.servlet;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.Enumeration;
import java.util.Locale;


public interface ServletRequest {

public Object getAttribute(String name);

public Enumeration getAttributeNames();

public String getCharacterEncoding();

public int getContentLength();

public String getContentType();

public ServletInputStream getInputStream() throws IOException;

public String getParameter(String name);

public Enumeration getParameterNames();

public String[] getParameterValues(String name);

public String getProtocol();

public String getScheme();

public String getServerName();

public int getServerPort();

public BufferedReader getReader() throws IOException;

public String getRemoteAddr();

public String getRemoteHost();

public void setAttribute(String name, Object o);

public void removeAttribute(String name);

public Locale getLocale();

public Enumeration getLocales();

public boolean isSecure();

public RequestDispatcher getRequestDispatcher(String path);

public String getRealPath(String path);

}
hj12 2003-10-07
  • 打赏
  • 举报
回复
ServletRequest我想应该在这里!
xijianyu 2003-10-07
  • 打赏
  • 举报
回复
我是想知道getXXX()方法的原码在哪个类里实现。
hj12 2003-10-07
  • 打赏
  • 举报
回复
楼主什么意思!我看不懂了,它就是servlet用来获的网页传递过来的参数的,如果你说它是那里来的,我现在的水平只能说它来只HTTP。
Schlemiel 2003-10-07
  • 打赏
  • 举报
回复
HttpServletRequest只是J2EE规范要求的一个接口,你的servlet类真正拿到的是HttpServletRequest的一个子类的对象。应用服务器会创建这个对象,再把它交给你的程序。
showerXP 2003-10-07
  • 打赏
  • 举报
回复
这样的话问题又回到开始了。jsp的内置对象是什么时候由谁创建的呢?
monbit 2003-10-07
  • 打赏
  • 举报
回复
那你不明白的还真多拉。。。呵呵。。。。。。你不会直接使用out,而不声明吧?这可是程序,而不是jsp页面。。。。。。那里还有什么内置对象亚。。。。
showerXP 2003-10-07
  • 打赏
  • 举报
回复
public class Hello extends HttpServlet……

从“class Hello”看出Hello是一个类,而jsp就直接调用了它。我想肯定有一个new对象的过程,但是在哪里呢?

PrintWriter out = response.getWriter();

out是jsp的一个内置对象,属于javax.servlet.jsp包中的JspWriter类。而该类已经import了,为什么还要申明呢?而且“response.getWriter();”是什么意思?

哪位讲解一下!

81,122

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧