认识什么是 JSP 称为 Servlet

发布于 2024-12-23 15:35:56 字数 165 浏览 0 评论 0原文

我有两个可以访问 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

爱已欠费 2024-12-30 15:35:56

您可以在同一参数上传递不同的值。

在 page1.jsp 中

<jsp:forward page="/MyServelt">
   <jsp:param name="action" value="incr" /> 
</jsp:forward/>

在 page2.jsp

<jsp:forward page="/MyServelt">
   <jsp:param name="action" value="decr" /> 
</jsp:forward/>

如果使用

标签,则添加 ,

<form method="post" action="/MyServlet">
  <input type="hidden" name="action" value="incr"/>
  .....
</form>

You could pass different value on same parameter.

In page1.jsp

<jsp:forward page="/MyServelt">
   <jsp:param name="action" value="incr" /> 
</jsp:forward/>

In page2.jsp

<jsp:forward page="/MyServelt">
   <jsp:param name="action" value="decr" /> 
</jsp:forward/>

If <form> tag is used then add <input type="hidden"/>,

<form method="post" action="/MyServlet">
  <input type="hidden" name="action" value="incr"/>
  .....
</form>
英雄似剑 2024-12-30 15:35:56

首先,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 or getRequestURI() method of request to get it but I have never used it so not sure about it.

苯莒 2024-12-30 15:35:56

在执行递增或递减操作的方法中使用 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

:)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文