a href="your target url"Link/a
成都创新互联公司是一家集网站建设,薛城企业网站建设,薛城品牌网站建设,网站定制,薛城网站建设报价,网络营销,网络优化,薛城网站推广为一体的创新建站企业,帮助传统企业提升企业形象加强企业竞争力。可充分满足这一群体相比中小企业更为丰富、高端、多元的互联网需求。同时我们时刻保持专业、时尚、前沿,时刻以成就客户成长自我,坚持不断学习、思考、沉淀、净化自己,让我们为更多的企业打造出实用型网站。
如果在servlet中:
PrintWriter out = res.getWriter();
out.println("a href='your target url'Link/a");
如果是连接自己项目中的,请注意相对路径的写法。建议加上context path.
那你要做的就是向这个URL发送数据就好,给个例子:
public class Httptest1 {
8
9 public static void main(String[] args) {
10
11 URL url = null ;
12 HttpURLConnection conn = null ;
13 OutputStream outStream = null ;
14 InputStream inStream = null ;
15
16 try {
17 url = new URL( " " );
18 conn = (HttpURLConnection) url.openConnection();
19 conn.setDoOutput( true );
20 conn.setDoInput( true );
21
22 String sendXml = " ?xml version=\ " 1.0 \ " encoding=\ " UTF - 16 \ " ?!DOCTYPE SigMailCommand SYSTEM \ " SigMail.dtd\ " " ; // XML数据
23 sendXml += " SigMailCommand Name=\ " checkuser\ " Param Name=\ " domainname\ " test.com.cn/Param " ;
24 sendXml += " Param Name=\ " username\ " admin/Param/SigMailCommand " ;
25
26 outStream = conn.getOutputStream();
27
28 // 准备通过CONN对象写入XML数据
29 BufferedWriter bw = new BufferedWriter( new java.io.OutputStreamWriter(outStream,
30 " UTF-16 " ));
31 bw.write(sendXml);
32 bw.flush();
33 bw.close();
34
35 // DataOutputStream dataOutStream = new DataOutputStream(outStream);
36 // dataOutStream.writeChars(xml);
37 // dataOutStream.flush();
38 // dataOutStream.close();
39
40
41 // 准备通过CONN对象读取返回的XML数据
42
43 inStream = conn.getInputStream();
44 StringBuffer returnXml = new StringBuffer( "" );
45 BufferedReader rd = new BufferedReader( new InputStreamReader(inStream,
46 " UTF-16 " ));
47 for (String line = null ; (line = rd.readLine()) != null ;) {
48 returnXml.append(line);
49 }
50 System.out.println(returnXml.toString());
51 rd.close();
52 } catch (IOException ex) {
53 ex.printStackTrace();
54 } finally {
55 try {
56 if (outStream != null )
57 outStream.close();
58 if (inStream != null )
59 inStream.close();
60 if (conn != null )
61 conn.disconnect();
62 } catch (IOException e) {
63 // TODO 自动生成 catch 块
64 e.printStackTrace();
65 }
66 }
67
68 }
69
70 }
1、在客户端用escape(encodeURIComponent(fieldValue))方法编码,例如:
复制代码代码如下:
title=escape(encodeURIComponent(title)); //这是js里的函数
url="%=request.getContextPath()%/print/printList!printTable.action?title="+title;
2、在服务端用java.net.URLDecoder.decode(getRequest().getParameter("title"),"UTF-8"),进行解码。
-----------------------------------------------------------------------------
parent.window.location.href 和 iframe中src的乱码问题。
要在这两个url地址中传中文,必须加编码,然后再解码。
编码:encodeURI(encodeURI("包含中文的串"))
解码:java.net.URLDecoder.decode("需要解码的串","utf-8");