Servlet + Jsp问题

发布于 2024-12-23 19:01:24 字数 66 浏览 0 评论 0原文

我有一个 JSP 页面,我想从其中的 onClick 执行一个 servlet 页面。任何人都可以帮助我,这怎么可能?

I have a JSP page, from where onClick I want to execute a servlet page. Can anybody help me, how can it possible ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(4

隔纱相望 2024-12-30 19:01:24
<input type="submit" value="Send" id="click" name="click"/>

if(request.getParameter("click")!=null)
{
    request.sendRedirect("URL");
}

或者

public class Dispatcher extends HttpServlet 
{
    public void doGet(HttpServletRequest request, HttpServletResponse response) 
    {
        RequestDispatcher dispatcher = 
        request.getRequestDispatcher("URL");
        if (dispatcher != null) dispatcher.forward(request, response);
    }
}

Google 搜索 request.sendRedirect("URL");request.getRequestDispatcher("URL"); 之间的区别

<input type="submit" value="Send" id="click" name="click"/>

if(request.getParameter("click")!=null)
{
    request.sendRedirect("URL");
}

or

public class Dispatcher extends HttpServlet 
{
    public void doGet(HttpServletRequest request, HttpServletResponse response) 
    {
        RequestDispatcher dispatcher = 
        request.getRequestDispatcher("URL");
        if (dispatcher != null) dispatcher.forward(request, response);
    }
}

Google search for the difference between request.sendRedirect("URL"); and request.getRequestDispatcher("URL");

羁绊已千年 2024-12-30 19:01:24

如果您不想重新加载当前页面或使用 window.location.href 属性执行重定向,则可以使用 AJAX 调用来调用 servlet。如果您想向服务器发送一些值,您可以在 AJAX 请求正文中发送它们,或者如果您决定重定向,则将它们作为查询字符串参数发送。

You could use an AJAX call to invoke the servlet if you don't want to reload the current page or perform a redirect using the window.location.href property. If you want to send some values to the server you could send them in the AJAX request body or as query string parameters if you decide to redirect.

黎夕旧梦 2024-12-30 19:01:24
<form method=GET action="servlet/nextPage">
some text here
<input type=submit>
</form>
<form method=GET action="servlet/nextPage">
some text here
<input type=submit>
</form>
与酒说心事 2024-12-30 19:01:24

您需要一个带有单个按钮的表单,并将表单发送到 servlet

,或者您可以使用简单的单击一些文本

您的 图像下的链接Servlet必须在web.xml中描述或者通过注解的方式才能被调用。

You need a form with single button, and send form to the servlet

or you can use simple <a href="yourServlet">some text to be clicked</a> or link under image

your Servlet must be described in web.xml or by annotation to let it be called.

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