包含@postcjava的词条

博主:adminadmin 2022-12-23 21:48:08 61

今天给各位分享@postcjava的知识,其中也会对进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!

本文目录一览:

java 测试post请求 在body里面传递参数怎么设置,怎么接收

package wzh.Http;import java.io.BufferedReader;import java.io.IOException;import java.io.InputStreamReader;import java.io.PrintWriter;import java.net.URL;import java.net.URLConnection;import java.util.List;import java.util.Map;public class HttpRequest { /** * 向指定URL发送GET方法的请求 * * @param url * 发送请求的URL * @param param * 请求参数,请求参数应该是 name1=value1name2=value2 的形式。 * @return URL 所代表远程资源的响应结果 */ public static String sendGet(String url, String param) { String result = ""; BufferedReader in = null; try { String urlNameString = url + "?" + param; URL realUrl = new URL(urlNameString); // 打开和URL之间的连接 URLConnection connection = realUrl.openConnection(); // 设置通用的请求属性 connection.setRequestProperty("accept", "*/*"); connection.setRequestProperty("connection", "Keep-Alive"); connection.setRequestProperty("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)"); // 建立实际的连接 connection.connect(); // 获取所有响应头字段 Map map = connection.getHeaderFields(); // 遍历所有的响应头字段 for (String key : map.keySet()) { System.out.println(key + "---" + map.get(key)); } // 定义 BufferedReader输入流来读取URL的响应 in = new BufferedReader(new InputStreamReader( connection.getInputStream())); String line; while ((line = in.readLine()) != null) { result += line; } } catch (Exception e) { System.out.println("发送GET请求出现异常!" + e); e.printStackTrace(); } // 使用finally块来关闭输入流 finally { try { if (in != null) { in.close(); } } catch (Exception e2) { e2.printStackTrace(); } } return result; } /** * 向指定 URL 发送POST方法的请求 * * @param url * 发送请求的 URL * @param param * 请求参数,请求参数应该是 name1=value1name2=value2 的形式。 * @return 所代表远程资源的响应结果 */ public static String sendPost(String url, String param) { PrintWriter out = null; BufferedReader in = null; String result = ""; try { URL realUrl = new URL(url); // 打开和URL之间的连接 URLConnection conn = realUrl.openConnection(); // 设置通用的请求属性 conn.setRequestProperty("accept", "*/*"); conn.setRequestProperty("connection", "Keep-Alive"); conn.setRequestProperty("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)"); // 发送POST请求必须设置如下两行 conn.setDoOutput(true); conn.setDoInput(true); // 获取URLConnection对象对应的输出流 out = new PrintWriter(conn.getOutputStream()); // 发送请求参数 out.print(param); // flush输出流的缓冲 out.flush(); // 定义BufferedReader输入流来读取URL的响应 in = new BufferedReader( new InputStreamReader(conn.getInputStream())); String line; while ((line = in.readLine()) != null) { result += line; } } catch (Exception e) { System.out.println("发送 POST 请求出现异常!"+e); e.printStackTrace(); } //使用finally块来关闭输出流、输入流 finally{ try{ if(out!=null){ out.close(); } if(in!=null){ in.close(); } } catch(IOException ex){ ex.printStackTrace(); } } return result; } }//函数调用时填入URL和参数(参数非必须)就可以获取返回的数据,发送post请求调用示例String result=HttpRequest.sendPost("/telematics/v3/weather?location=%E5%8C%97%E4%BA%ACoutput=jsonak=E4805d16520de693a3fe707cdc962045","")

C++通过POST方式URL链接传值到JAVA中文乱码

这是我在做web开发时候遇到的乱码问题的一些解决方案,我感觉无非就这么几种了吧:

1.显示把form表单的提交方式改为post

2.jsp页面添加:

%@ page language="java" import="java.util.*" contentType="text/html; charset=GBK" pageEncoding="GBK"%

3.struts2.xml中添加constant name="struts.i18n.encoding" value="GBK"/'

4.在web.xml中添加字符编码过滤器

5.通过javascript传递参数如果有中文:

使用编码URL的方式来防止乱码

function returnToLast(id, name) {

opener.document.location.href=encodeURI("addActivity.action?ID=" + id + "name="

+ name + "");

}

java 连续发送post请求

不知道你说的意思是不是这个效果。这个也曾困扰过我。这里提交按钮把表单提交,页面post到后台,在这个表单的另一个button能触发链接到另一个页面(也可以是应用,也是一种post),不知道对你是否有启发。见我代码:

!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" ""

%@page contentType="text/html;charset=utf-8"%

%@page isELIgnored="false" %

%@taglib uri="" prefix="c"%

%request.setCharacterEncoding("gb2312");%

%response.setCharacterEncoding("gb2312");%

html xmlns=""

head

style type="text/css"

body {

background: #FFF;

color: #000;

font: 12px Verdana, Arial, Helvetica, sans-serif;

margin: 0;

padding: 0;

}

a:link, a:visited {

color: #FF2A84;

text-decoration: underline;

}

a:hover, a:active {

color: #FFF;

text-decoration: none;

background: #FF2A84;

}

#navigation {

background: #FFF;

border-bottom: 1px solid #A1A1A1;

margin: 1em 0 0;

padding: 0.6em 0 0;

font-weight: bold;

}

#navigation ul, #navigation ul li {

list-style: none;

margin: 0;

padding: 0;

}

#navigation ul {

padding: 5px 0 5px;

text-align: left;

}

#navigation ul li {

display: inline;

}

#navigation ul li a {

background: url(tableft.gif) no-repeat left top;

color: #FFF;

text-decoration: none;

padding: 5px 0;

}

#navigation ul li span {

background: url(tabright.gif) no-repeat right top;

padding: 5px 7px 5px 3px;

margin: 4px 0 4px 4px;

}

#navigation ul li a:hover span {

text-decoration: underline;

background-position: 100% -75px;

}

#navigation ul li a:hover {

background-position: 0 -75px;

}

#navigation #current a {

background-position: 0 -150px;

}

#navigation #current a span {

background-position: 100% -150px;

}

* html #navigation ul li a {

padding: 0;

}

/style

script type="text/javascript"

function go(){

location.href="/21com/entr_admin_2page.html";

}

/script

/head

body

p align="right"a href="login.jsp" style="text-decoration:none;"退出/a/p

div id="navigation"

ul

liimg src="logo.jpg" width="400px"/img/li

lia href="home.html"span首页/span/a/li

li id="current"a href="/21com/entrance.do"span考勤/span/a/li

lia href="/21com/emplyee.do"span员工/span/a/li

lia href="self.html"span个人设置/span/a/li

/ul

/div

h1font color="red"设置考勤时段/font/h1

form action="/21com/entr_setting.do" method="POSt"

table

tr

td最晚上班时间:/td

tdinput type="text" name="late_time" //td

/tr

tr

td最早下班时间:/td

tdinput type="text" name="early_time" //td

/tr

tr

td每日最少工作时间:/td

tdinput type="text" name="little_time" //td

/tr

tr

td colspan="2"input type="submit" value="提交" /input/td

tdinput type="button" onclick="go()" value="取消"/input/td

/tr

/table

/form

hr/

h4font color="blue"现在考勤时段:/font/h4

table border="1" bordercolor="gray" cellspacing="0" width="80%"

tr bgcolor="gray"

tdfont color="white"b最晚上班时间/b/font/td

tdfont color="white"b最早下班时间/b/font/td

tdfont color="white"b每日最少工作时间/b/font/td

/tr

tr

td${periods.late_time}/td

td${periods.early_time}/td

td${periods.little_time}/td

/tr

/table

/body

/html

@postcjava的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于、@postcjava的信息别忘了在本站进行查找喔。

The End

发布于:2022-12-23,除非注明,否则均为首码项目网原创文章,转载请注明出处。