servlet doGet doPost区别

本文详细解释了Servlet的生命周期中的关键方法,包括init、service、doGet、doPost及destroy等,并探讨了它们之间的区别与联系。同时,还讨论了GET与POST请求的区别及其应用场景。
如转贴中所描述,在 servlet生命周期中,service方法进行判断调用doGet还是doPost方法
init()
service() {goGet() & doPost()}
destroy()
技术实现上,可以doGet/doPost使用相同的代码
如写一个doXXX,在doGet/doPost中均使用doXXX

Author Topic: Differences Between doGet(),doPost(),service()
ganapathy gopinathan
greenhorn
Member # 78471

 

posted September 28, 2004 07:52 AM      Profile for ganapathy gopinathan   Email ganapathy gopinathan   Send New Private Message      Edit/Delete Post  Reply With Quote 


Hi all,

Anyone plz help me to understand the differences between the doGet(),doPost(),and service() methods.

Thank u
gopi


Posts: 30 | Registered: Aug 2004  |  IP: Logged
sanjeevmehra mehra
ranch hand
Member # 79249

 

posted September 28, 2004 08:09 AM      Profile for sanjeevmehra mehra   Email sanjeevmehra mehra   Send New Private Message      Edit/Delete Post  Reply With Quote 

init()
service() {goGet() & doPost())
destroy()
are the lifecycle methods. init() & destroy() are called once in lifetime. And service() method is called whenever a request comes. If request is through the Get method, service() method calls (pass that request to) doGet() and if request is through post method service() method calls (pass that request to the) doPost() method.


thanks & regards,
sanjeev.


Posts: 88 | Registered: Aug 2004  |  IP: Logged

--------------------

thanks & regards,
Sanjeev.

Stan James
(instanceof Sidekick)
Member # 44095

 

posted September 28, 2004 10:07 AM      Profile for Stan James   Author's Homepage     Send New Private Message      Edit/Delete Post  Reply With Quote 

Technically you can make doGet and doPost act identically. It's not uncommon to see both of those methods call doProcess or some other method you make up, allowing users to get or post at will.

The inventors of HTTP saw them as very different however. GET operations must be "idempotent" which just means they have no side effects and repeated calls should give the same result. A pure query in other words. POST operations should be used to send information to the server that will change the state of some object or data store.

HERE is an article on the topic that I happened to be reading right before I saw your note. The inventors of HTTP promote a web application architecture called REST (Representational State Transfer) that assigns very particular meaning to all the HTTP verbs - GET, POST, PUT, HEAD, etc - and further tells us that these are all we need.


Posts: 6763 | Registered: Jan 2003  |  IP: Logged

--------------------

A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi

Kathy Sierra
Cowgirl and Author
Member # 37766

 

posted September 28, 2004 10:19 AM      Profile for Kathy Sierra   Author's Homepage   Email Kathy Sierra   Send New Private Message      Edit/Delete Post  Reply With Quote 
quote:

Originally posted by Stan James:
GET operations must be "idempotent" which just means they have no side effects and repeated calls should give the same result.




I just wanted to make one tiny clarification--I know what you meant Stan, but I just wanted to make sure it's clear to everyone: HTTP GET operations do *not* need to always "give the same result", in terms of the *response*. The *response* can be different with each GET, as long as there are no side-effects. So what you said is correct (no side effects, pure query, etc.); I'm just making sure that everyone knows that "repeated calls should give the same result" does not mean "same RESPONSE".

cheers and thanks for the good link!
-Kathy


Posts: 1716 | Registered: Oct 2002  |  IP: Logged
ganapathy gopinathan
greenhorn
Member # 78471

 

posted September 29, 2004 04:53 PM      Profile for ganapathy gopinathan   Email ganapathy gopinathan   Send New Private Message      Edit/Delete Post  Reply With Quote 

what is the difference between 'service()' and 'doGet()'(or 'doPost()')?


Posts: 30 | Registered: Aug 2004  |  IP: Logged
Adeel Ansari
ranch hand
Member # 78839

 

posted September 29, 2004 10:46 PM      Profile for Adeel Ansari   Author's Homepage   Email Adeel Ansari   Send New Private Message      Edit/Delete Post  Reply With Quote 

Now you haven't got the difference right. ok then read the docs or some tutorial, book.
Again there is no better substitute.

cheers


Posts: 2321 | Registered: Aug 2004  |  IP: Logged

--------------------

The code I wrote nine months ago sucks. And I'm happy about it. — Bear Bibeault

sanjeevmehra mehra
ranch hand
Member # 79249

 

posted September 30, 2004 01:29 AM      Profile for sanjeevmehra mehra   Email sanjeevmehra mehra   Send New Private Message      Edit/Delete Post  Reply With Quote 
quote:

what is the difference between 'service()' and 'doGet()'(or 'doPost()')?


service(), doGet() and doPost() are methods, and are used to do operations (methods are to do operations/task, hope that's clear).
you can perform the same or different task in doGet() & in doPost() as per your need(requirement). So, there is no difference b/w doGet() & doPost() and you need to implement these methods as per your requirements. At the moment you should know when doGet() would be called & when doPost() would be called and how.


quote:

Now you haven't got the difference right. ok then read the docs or some tutorial, book.
Again there is no better substitute.


do the same & share your doubts.



thanks & regards.

--------------------

thanks & regards,
Sanjeev.


Posts: 88 | Registered: Aug 2004  |  IP: Logged
ganapathy gopinathan
greenhorn
Member # 78471

 

posted September 30, 2004 08:14 AM      Profile for ganapathy gopinathan   Email ganapathy gopinathan   Send New Private Message      Edit/Delete Post  Reply With Quote 
Correct me if i m wrong,

GET():

- 'Get' is used to send the form data with the request itself.
- only 256 characters are allowed.
- when there is no such class or nothing to satisfy the request the data is lost.

POST():
- first header is send, the form fields are send after the finding the something that satisfies the request.
- i think there is no limitation on no of charactors to be sent.
- if there is nothing to satisfy the request then the data is not sent.

let me know in which conditions or situation we have to use the service()?

Thanks
gopinathan

Posts: 30 | Registered: Aug 2004  |  IP: Logged
Adeel Ansari
ranch hand
Member # 78839

 

posted October 01, 2004 12:53 AM      Profile for Adeel Ansari   Author's Homepage   Email Adeel Ansari   Send New Private Message      Edit/Delete Post  Reply With Quote 
hey gopi i found something simple and somewhat complete for you. here is that,

After the servlet is initialized, the container may keep it ready for handling client
requests. When client requests arrive, they are delegated to the servlet through the
service()method, passing the request and response objects as parameters. In the
case of HTTP requests, the request and response objects are implementations of
HttpServletRequest and HttpServletResponse respectively. In the
HttpServlet class, the service() method invokes a different handler method for
each type of HTTP request, doGet() method for GET requests, doPost() method for
POST requests, and so on.


some more,


GET method

The GET method is used to retrieve a resource (like an image or an HTML page) from
the server, which is specified in the request URL. When the user types the request
URL into the browser's location field or clicks on a hyperlink, the GET method is
triggered. If a tag is used, the method attribute can be specified as "GET" to cause the
browser to send a GET request. Even if no method attribute is specified, the browser
uses the GET method by default.
We can pass request parameters by having a query string appended to the request
URL, which is a set of name-value pairs separated by an "&" character. Here we have passed the parameters studname and studno, which have the values
"Tom" and "123" respectively. Because the data passed using the GET method is
visible inside the URL, it is not advisable to send sensitive information in this manner.
The other restrictions for the GET method are that it can pass only text data and not more than 255 characters (i read somewhere that it depends on browser support).


POST method
The purpose of the POST method is to "post" or send information to the server. It is
possible to send an unlimited amount of data as part of a POST request, and the type of
data can be binary or text.
This method is usually used for sending bulk data, such as uploading files or updating
databases. The method attribute of the <form> tag can be specified as "POST" to
cause the browser to send a POST request to the server.
Because the request parameters are sent as part of the request body, it is not visible
as part of the request URL, which was also the case with the GET method.

[ October 01, 2004: Message edited by: adeel ansari ]

--------------------

The code I wrote nine months ago sucks. And I'm happy about it. — Bear Bibeault


Posts: 2321 | Registered: Aug 2004  |  IP: Logged
srinivasan doraiswamy
greenhorn
Member # 82476

 

posted October 01, 2004 01:23 AM      Profile for srinivasan doraiswamy        Edit/Delete Post  Reply With Quote 
when the req is received by the service method, req and res are cast to their http counter parts and service method with http req and res is invoked, this method directs the request to the appropriate method based on get or post, actually u no need to implement the service method instead u should implement these subsidiary methods (get or post) in ur servlet
Posts: 5 | Registered: Sep 2004  |  IP: Logged
All times are MST (US) = UTC - 0700  
Post New Topic  Post A Reply Close Topic    Move Topic    Delete Topic next oldest topic   next newest topic
Hop To:

 

 

Copyright © 1998-2006 Paul Wheaton
Infopop Corporation
Ultimate Bulletin Board TM 6.1.0.3

 

CodeWranglers

 

内容概要:本文围绕“基于交流潮流的电力系统多元件N-k故障模型研究”展开,深入探讨了利用Matlab代码实现电力系统在发生多个关键元件同时故障(即N-k故障)情况下的交流潮流计算与故障分析方法。该模型不仅考虑了传统潮流方程的非线性特性,还引入了故障约束条件,能够精确模拟复杂多样的故障场景,如短路、断线等,进而评估电网在极端运行条件下的稳态与动态行为。研究通过构建典型电力系统算例,验证了所提模型在故障筛选、脆弱性识别及系统恢复策略制定方面的有效性,为电力系统安全评估、风险预警和防御体系构建提供了坚实的理论依据和技术支撑。此外,模型具备良好的扩展性,可进一步应用于连锁故障传播分析、恶意攻击模拟等高级安全分析领域。; 适合人群:具备电力系统分析基础理论知识和Matlab编程能力的高校研究生、科研院所研究人员以及电力公司从事电网规划、运行与安全管理的技术人员,特别适用于开展电力系统安全稳定、可靠性评估与应急响应机制研究的专业人士。; 使用场景及目标:①开展电力系统在多重故障条件下的交流潮流仿真,评估系统电压稳定性、线路过载风险及负荷损失程度;②识别电网中的关键薄弱环节与脆弱元件,支撑电网加固改造与防御资源配置;③用于科研项目中的故障场景建模与算法验证,或作为教学案例帮助学生理解复杂故障下的系统响应机制。; 阅读建议:此资源以Matlab代码为核心实现手段,建议读者结合理论推导与代码实现进行对照学习,重点关注故障建模过程中雅可比矩阵的修正方法、故障注入方式及收敛性处理策略,建议在仿真中逐步增加故障数量与复杂度,深入理解N-k故障对系统潮流分布的影响规律,并尝试将其拓展至含新能源接入的现代电力系统场景中进行验证与优化。
【重要提示】本资源设置为0积分下载,若非0积分请勿轻易下载 亲爱的CSDN用户: 首先感谢你点进这个资源页面。我需要提前说明一个重要情况: 本资源原本已设置为“0积分下载”,即作者希望完全免费共享。但CSDN平台有时会根据文件的下载热度、文件大小、用户权限等因素,自动将部分资源的积分调整为非0数值(如1积分、2积分、5积分等)。这是平台系统的自动行为,而非作者本人的设定。 因此,如果你当前看到该资源的下载所需积分不是0(例如显示为1、2、3……),请谨慎决定是否下载。 如果你按照非0积分支付并下载后发现资源内容不符合预期、链接失效,或者实际上该资源本应是免费的,作者无法为此承担积分损失或退还操作。强烈建议:仅在页面显示为0积分时进行下载。 另外,本资源描述中并未直接提供具体的下载地址或外部链接,因为它本身是一个通过CSDN官方上传通道提交的文件/内容包。如果你看到描述中没有外部网盘地址,这是正常的——资源文件应通过CSDN内置的“下载”按钮获取。若因平台积分显示异常导致你支付了积分,请优先联系CSDN客服咨询积分退还政策,作者没有权限修改平台自动设定的积分值。 感谢你的理解与支持。技术分享本应开放,但受限于平台规则,特此提醒如上。祝学习进步!
内容概要:本文详细介绍了基于PyTorch实现的并行物理信息神经网络(PINNs)在NLS–MB方程孤子演化预测中的应用实例,系统阐述了模型架构设计、损失函数构造、训练流程优化及并行计算策略的实施过程。通过深度融合物理先验知识与深度学习框架,该方法有效求解了非线性薛定谔类偏微分方程,实现了对孤子动力学行为的高精度、高效率数值模拟与长期演化预测,充分展现了PINNs在处理复杂科学计算问题中的强大建模能力与泛化性能。; 适合人群:具备一定深度学习理论基础和偏微分方程求解经验,熟练掌握Python编程语言及PyTorch深度学习框架,从事计算物理、流体力学、光学通信或相关工程仿真的研究生、科研人员及高级技术人员。; 使用场景及目标:①深入理解如何将物理守恒律与控制方程作为硬约束嵌入神经网络,提升模型在稀疏数据下的泛化能力与物理一致性;②掌握PINNs在非线性孤子波、色散介质传播等复杂动力系统建模中的关键技术实现路径;③应用于量子物理、非线性光学、大气海洋动力学等领域中传统数值方法难以求解的高维、强非线性偏微分方程的正/反问题研究。; 阅读建议:建议读者结合文末提供的完整代码资源(可通过公众号“荔枝科研社”获取)进行动手实践,重点关注物理残差项在自动微分框架下的精确计算、多任务损失权重的平衡策略,并尝试迁移模型至其他类型的非线性演化方程以深化理解与应用能力。
内容概要:本文围绕LLC谐振变换器的变频移相混合控制模型展开研究,通过Simulink搭建完整的仿真模型,系统阐述了该控制策略的理论基础与实现方法。研究结合变频控制与移相控制的优点,旨在提升LLC谐振变换器在宽负载范围内的转换效率与系统稳定性,深入分析其在高频高效电源系统中的动态响应特性与优化潜力。文中详细展示了控制逻辑设计、关键参数整定及仿真验证过程,有助于读者全面掌握LLC变换器的工作机理与先进控制技术的应用。; 适合人群:具备电力电子技术、自动控制理论及仿真建模基础的科研人员与工程师,特别适用于从事高频电源、新能源变换系统研发的技术人员,以及电力电子与电气工程方向的研究生及以上学历人员。; 使用场景及目标:①深入理解LLC谐振变换器的核心工作原理及其在轻载与重载工况下的控制挑战;②掌握变频与移相混合控制策略的设计思路、协同机制与仿真建模技巧;③应用于高频DC-DC变换器、电动汽车车载充电机、光伏微逆变器及高效开关电源等高性能电力电子系统的研发与性能优化。; 阅读建议:建议读者结合提供的Simulink仿真模型逐步操作,重点观察系统在不同负载条件下的频率调节与相位调节响应,深入分析效率曲线与谐振腔波形变化,进而掌握控制参数对系统性能的影响规律,可进一步拓展至其他谐振拓扑(如Series Resonant、LCL等)的混合控制策略研究。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值