提交表单使用post但是url里面还是有参数
我自己在练习的时候发现一个问题,我使用post的方式进行表单提交,但是在浏览器的URL里面还是有参数。
具体代码如下
浏览器的结果如图:
好吧 网络比较卡图片上传不上来 我把URL贴出来吧
http://localhost:9080/webDemo/request1.jsp?name=hahahahha&gender=male&color=black&color=green&color=yellow&color=white&country=China
具体代码如下
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><%@page
language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<html>
<head>
<title>form2</title>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<meta name="GENERATOR"
content="Rational Application Developer for WebSphere Software">
</head>
<body>
<form id="form2" menthod="post" action="request1.jsp">
Uesr Name: <br/>
<input type="text" name="name"><hr/>
Gender:
Male <input type="radio" name="gender" value="male">
female <input type="radio" name="gender" value="female"><hr/>
Which color do you like best:<br/>
Black <input type="checkbox" name="color" value="black">
Green <input type="checkbox" name="color" value="green">
Yellow <input type="checkbox" name="color" value="yellow">
White <input type="checkbox" name="color" value="white"><hr/>
Where do you come from:<br/>
<select name="country">
<option value="China">China</option>
<option value="Japan">Japan</option>
<option value="India">India</option>
</select><hr/>
<input type="submit" value="Submit">
<input type="reset" value="Reset">
</form>
</body>
</html>
<%@ page import="java.util.*"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><%@page
language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<html>
<head>
<title>request1</title>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<meta name="GENERATOR"
content="Rational Application Developer for WebSphere Software">
</head>
<body>
<%
Enumeration<String> headerNames = request.getHeaderNames();
while(headerNames.hasMoreElements()){
String headerName = headerNames.nextElement();
out.println(headerName + "-->" + request.getHeader(headerName) + "<br/>");
}
out.println("<hr/>");
//for simple chinese u can set gb2312
request.setCharacterEncoding("gb2312");
//get the value from this form
String name = request.getParameter("name");
String gender = request.getParameter("gender");
String[] color = request.getParameterValues("color");
String nation = request.getParameter("country");
%>
Your name is: <%=name%><hr>
Your gender is: <%=gender%><hr>
Your favorite color is:
<%
for(String c : color){
out.println(c+ " ");
}
%><hr/>
Your country is: <%=nation%><hr/>
</body>
</html>
浏览器的结果如图:
好吧 网络比较卡图片上传不上来 我把URL贴出来吧
http://localhost:9080/webDemo/request1.jsp?name=hahahahha&gender=male&color=black&color=green&color=yellow&color=white&country=China
...全文
相关推荐
表单提交中get和post的区别
在get方式中,参数数据队列会被加到提交表单的ACTION属性所指的URL中,值和表单内各个字段一一对应,在URL中可以看到。
window.open()实现post传递参数
它接收URL、窗口名以及需要传递的参数作为输入,创建并提交表单,从而实现了POST方式的数据传递。
使用jquery提交form表单并自定义action的方法
在本篇文章中,我们将探讨如何使用jQuery来提交HTML的`form`表单,并自定义其`action`属性,以便在提交表单时传递额外的参数。
浅析get与post的一些特殊情况
POST方法: - POST方法将表单数据放在HTTP请求的主体部分,而不是URL中。当使用POST提交表单,URL中的参数不受表单数据影响。
java中用URLConnection_类post方式提交表单
三、使用URLConnection类post方式提交表单的步骤1. 创建URL对象:使用java.net.URL类创建一个URL对象,该对象指定了要连接的服务器和请求的资源。2.


