认识什么是 JSP 称为 Servlet
我有两个可以访问 Servlet 的 JSP 页面。现在,我希望当 JSP 1 访问 Servlet 时,Servlet 将执行某种类型的工作(例如递增 int),而当 JSP 2 访问 Servlet 时,它将执行某种其他类型的工作(例如递减 int) 。
任何人都可以帮助我指定它是如何可能的吗?
I have two JSP pages that can access a Servlet. Now, I want when JSP 1 access the Servlet, Servlet will do some one kind of job (for example increment an int) and when JSP 2 will access the Servlet, it will do some other kind of job (for example decrement an int).
Can anybody help me by specifying how is it possible ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以在同一参数上传递不同的值。
在 page1.jsp 中
在 page2.jsp
如果使用
You could pass different value on same parameter.
In page1.jsp
In page2.jsp
If
<form>
tag is used then add<input type="hidden"/>
,首先,Servlet 不是页面。
其次,解决您的问题的方法是将请求中的参数从 jsp 页面传递到 servlet,该参数有助于识别请求的发出位置,并通过使用此参数决定您应该执行哪个操作,或者您也可以使用
referer请求的
标头或请求的getRequestURI()
方法来获取它,但我从未使用过它,所以不确定。First of all Servlets are not page.
Second, solution to your problem will be to pass a parameter in request from jsp page to servlet that helps in identifying from where the request has been made and by using this parameter decide which operation you should do or you can also use
referer
header of request orgetRequestURI()
method of request to get it but I have never used it so not sure about it.在执行递增或递减操作的方法中使用 synchronous 关键字。
这更像是数据库事务中的隔离。其次,要决定到底要做什么,
您可以使用请求参数,例如 -domain/myservlet?action=increment
:)
use synchronous keyword to the method that does the increment or decrement operation.
This is more like isolation in database transaction. Secondly to decide what exactly to do,
You can use the request parameters eg - domain/myservlet?action=increment
:)