码迷,mamicode.com
首页 > 其他好文 > 详细

表单Form传参数

时间:2015-08-25 12:10:26      阅读:266      评论:0      收藏:0      [点我收藏+]

标签:表单form传参数

    在提交Form表单时,往往我们需要带一些参数传出去进行处理

下面给出关键代码,演示一下。

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<html>
<head>
</head>
<script type="text/javascript">
function send(){
var message="test form";
myForm.action = "/WebTest001/myServlet?msg=" + message;
myForm.submit();
}
</script>
<body>
<form name="myForm" action="/WebTest001/myServlet" method="post">
<input type="button" value="send" onclick="send();">
</form>
</body>
</html>

这里面用到了form的name属性

另外需要注意action最前面需要加上包名,否则404,之前看到有网友不加也可以使用??

有懂得麻烦告知。

submit即开始提交form


servlet接收参数

public class TestServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
response.getWriter().append("Served at: ").append(request.getContextPath());
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String msg = request.getParameter("msg").toString();
System.out.println("msg = " + msg);
}
}

只需按照参数名称取即可


技术分享

本文出自 “爬过山见过海” 博客,请务必保留此出处http://670176656.blog.51cto.com/4500575/1687846

表单Form传参数

标签:表单form传参数

原文地址:http://670176656.blog.51cto.com/4500575/1687846

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!