才开始学,代码中有几句不是很理解,还请各位GG,JJ指教。

zhoulf 2003-04-03 11:33:02
才开始学,代码中有几句不是很理解,还请各位大哥指教。
1、HashMap parameterMap = new HashMap( request.getParameterMap() ) ;
2、HttpSession session = request.getSession( true ) ;
3、ServletContext sc ;
RequestDispatcher rd ;
sc = getServletContext( ) ;
rd = sc.getRequestDispatcher( pageName ) ;
rd.forward( newRequest, newResponse ) ;
...全文
45 9 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
tingod 2003-04-03
  • 打赏
  • 举报
回复
1、getParameterMap
public java.util.Map getParameterMap()
Returns a java.util.Map of the parameters of this request. Request parameters are extra information sent with the request. For HTTP servlets, parameters are contained in the query string or posted form data.
Returns:
an immutable java.util.Map containing parameter names as keys and parameter values as map values. The keys in the parameter map are of type String. The values in the parameter map are of type String array.

2、public HttpSession getSession(boolean create)
Returns the current HttpSession associated with this request or, if if there is no current session and create is true, returns a new session.
If create is false and the request has no valid HttpSession, this method returns null.

To make sure the session is properly maintained, you must call this method before the response is committed. If the container is using cookies to maintain session integrity and is asked to create a new session when the response is committed, an IllegalStateException is thrown.

Parameters:
true - to create a new session for this request if necessary; false to return null if there's no current session
Returns:
the HttpSession associated with this request or null if create is false and the request has no valid session

3、这时一段转向语句,可以用来传递request值。例:
/** 重定向 */
public void redirect(HttpServletRequest request, HttpServletResponse response, String directory) throws ServletException, IOException {
RequestDispatcher redirectory = getServletContext().getRequestDispatcher(directory);
redirectory.forward(request,response);
}
zhoulf 2003-04-03
  • 打赏
  • 举报
回复
你还看懂一句嘛,说来听听社
DemonLeo 2003-04-03
  • 打赏
  • 举报
回复
看到现在没人跟贴,我来顶一下,你起点好高,3句只看懂了1句,脸特红,我还是跟你学得了。:)
kobeli 2003-04-03
  • 打赏
  • 举报
回复
我认为你的编程手法不可取!
foolbirds 2003-04-03
  • 打赏
  • 举报
回复
session对象存在于一个会话当中,如果有必要某个对象在会话中经常用到,当然这个方法是最好的
,也正是由于它存在于整个会话,所以会耗费资源。
cjt0226 2003-04-03
  • 打赏
  • 举报
回复
2、得到当前session对象,用这种方法,如果session不存在,会新建一个session对象,这种方法会耗费服务器资源,不可取;
那么应该用什么方法呢?
zhxx 2003-04-03
  • 打赏
  • 举报
回复
2.得到一个会话,如果不存在则创建

3 ServletContext 用于写日志或者分支处理请求时同servlet容器进行通信
RequestDispatcher 把请求导向服务器上的某个资源
sc = getServletContext( ) ; 从ServletConfig接口得到ServletContext对象
rd = sc.getRequestDispatcher( pageName ) ;返回指定资源的RequestDispatcher,参数
必须以"/" 开始,它相对于servlet根目录
rd.forward( newRequest, newResponse ) ;从一个servlet到另一个servlet或jsp,htm传递请求
shaopin 2003-04-03
  • 打赏
  • 举报
回复
1、返回一个哈希映射集合;
2、得到当前session对象,用这种方法,如果session不存在,会新建一个session对象,这种方法会耗费服务器资源,不可取;
3、转向语句,类同response.redirect()
zhoulf 2003-04-03
  • 打赏
  • 举报
回复
那位能帮我翻译一下吗,E文有点差。

81,122

社区成员

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

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