jsp中的href标记,并通过单击href标记传递数据 [英] href tags in jsp's and passing data by clicking on href tag

查看:130
本文介绍了jsp中的href标记,并通过单击href标记传递数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的程序

<form method="post">
Movie Name :<input type="text" name="movie"/><br>
Hero:<input type="text" name="hero"><br>
Director:<input type="text" name="dir"><br>

<a href="insert.jsp">Insert</a>
<a href="update.jsp">update</a>
<a href="delete.jsp">Delete</a>

当我单击任何href链接时,也应将上述文本框的值传送到该特定的jsp页面 我使用了getparameter方法,但是我没有得到输入的内容,但是它们使用的是空值

when i click on the any of the href link the values of above text boxes should also to be carried to that particular jsp page i used getparameter method but i am not getting what i entered but they are taking null values

推荐答案

这是因为您的href元素只是重定向到其他页面-表单的数据被废弃了.

This is because your href elements are simply redirecting to these other pages -- the form's data is scrapped.

您想要做的是允许提交表单-您将在Servlet的doPost()实现中接收值,然后在该方法中,应该通过(可能)在其中添加值来重定向到页面. URL,例如:

What you want to do is allow the form to be submitted -- you will receive the values in your Servlet's doPost() implementation, and in that method, you should then redirect to the page by, perhaps, adding the values in the URL, for instance:

insert.jsp?movie=jaws&hero=hercules&director=spielberg

然后这些值将可用于该页面.

The values will then be available to that page.

根据我的最新评论,要在没有POST/servlet的情况下执行此操作,您的代码将类似于启用jQuery的代码:

based on my latest comment, to do this without POST/servlets, your code would look like that with jQuery enabled:

<form method="get" id="myForm">
    Movie Name :<input type="text" name="movie"/><br>
    Hero:<input type="text" name="hero"><br>
    Director:<input type="text" name="dir"><br>

    <a href="insert.jsp">Insert</a>
    <a href="update.jsp">update</a>
    <a href="delete.jsp">Delete</a>
</form>
<script>
$('#myForm A').click(function(e)
{
   e.preventDefault(); // prevent the link from actually redirecting

   var destination = $(this).attr('href');
   $('#myForm').attr('action', destination);
   $('#myForm').submit();
});
</script>

这篇关于jsp中的href标记,并通过单击href标记传递数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆