用java怎么实现与浏览器的数据交互: 20
简单意思就是用java开发的cs应用小程序的一个数据怎么传到IE浏览器页面.cs应用小程序和IE浏览器(jsp)页面是没有关联的。怎么把cs应用程序的string值传到j...
简单意思就是用java开发的cs应用小程序的一个数据怎么传到IE浏览器页面.
cs应用小程序和IE浏览器(jsp)页面是没有关联的。怎么把cs应用程序的string值传到jsp页面的input下面的text文本框里面。
如图
难道是我的意思没表达清楚吗?怎么大家全部都理解错了。
1、cs小程序监听到的称重数据是不进数据库的,小程序和IE交互数据这中间是没牵涉到数据库,所以请大家不要往数据库方面向;
2、web系统(jsp)是买的,供应商不提供代码,所以jsp是没办法改的,所以请大家别再用request.setAttribute()这个方法了;
3、其实很简单就是cs程序和jsp页面交互数据的一个功能。 展开
cs应用小程序和IE浏览器(jsp)页面是没有关联的。怎么把cs应用程序的string值传到jsp页面的input下面的text文本框里面。
如图
难道是我的意思没表达清楚吗?怎么大家全部都理解错了。
1、cs小程序监听到的称重数据是不进数据库的,小程序和IE交互数据这中间是没牵涉到数据库,所以请大家不要往数据库方面向;
2、web系统(jsp)是买的,供应商不提供代码,所以jsp是没办法改的,所以请大家别再用request.setAttribute()这个方法了;
3、其实很简单就是cs程序和jsp页面交互数据的一个功能。 展开
6个回答
展开全部
看看java.net.HttpURLConnection这个类的用法,能够达到你的要求:
下面是一个例子:
1. package com.sw.study.urlConnection;
2.
3. import java.io.BufferedReader;
4. import java.io.InputStreamReader;
5. import java.io.OutputStream;
6. import java.net.HttpURLConnection;
7. import java.net.URL;
8. import java.net.URLConnection;
9. import java.util.HashMap;
10. import java.util.Map;
11.
12. public class URLConnectionUtil {
13.
14. private static final String SERVLET_POST = "POST" ;
15. private static final String SERVLET_GET = "GET" ;
16. private static final String SERVLET_DELETE = "DELETE" ;
17. private static final String SERVLET_PUT = "PUT" ;
18.
19. private static String prepareParam(Map<String,Object> paramMap){
20. StringBuffer sb = new StringBuffer();
21. if(paramMap.isEmpty()){
22. return "" ;
23. }else{
24. for(String key: paramMap.keySet()){
25. String value = (String)paramMap.get(key);
26. if(sb.length()<1){
27. sb.append(key).append("=").append(value);
28. }else{
29. sb.append("&").append(key).append("=").append(value);
30. }
31. }
32. return sb.toString();
33. }
34. }
35.
36. public static void doPost(String urlStr,Map<String,Object> paramMap ) throws Exception{
37. URL url = new URL(urlStr);
38. HttpURLConnection conn = (HttpURLConnection)url.openConnection();
39. conn.setRequestMethod(SERVLET_POST);
40. String paramStr = prepareParam(paramMap);
41. conn.setDoInput(true);
42. conn.setDoOutput(true);
43. OutputStream os = conn.getOutputStream();
44. os.write(paramStr.toString().getBytes("utf-8"));
45. os.close();
46.
47. BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream()));
48. String line ;
49. String result ="";
50. while( (line =br.readLine()) != null ){
51. result += "\n"+line;
52. }
53. System.out.println(result);
54. br.close();
55.
56. }
57.
58. public static void doGet(String urlStr,Map<String,Object> paramMap ) throws Exception{
59. String paramStr = prepareParam(paramMap);
60. if(paramStr == null || paramStr.trim().length()<1){
61.
62. }else{
63. urlStr +="?"+paramStr;
64. }
65. System.out.println(urlStr);
66. URL url = new URL(urlStr);
67. HttpURLConnection conn = (HttpURLConnection)url.openConnection();
68. conn.setRequestMethod(SERVLET_PUT);
69. conn.setRequestProperty("Content-Type","text/html; charset=UTF-8");
70.
71. conn.connect();
72. BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream()));
73. String line ;
74. String result ="";
75. while( (line =br.readLine()) != null ){
76. result += "\n"+line;
77. }
78. System.out.println(result);
79. br.close();
80. }
81.
82. public static void doPut(String urlStr,Map<String,Object> paramMap) throws Exception{
83. URL url = new URL(urlStr);
84. HttpURLConnection conn = (HttpURLConnection)url.openConnection();
85. conn.setRequestMethod(SERVLET_PUT);
86. String paramStr = prepareParam(paramMap);
87. conn.setDoInput(true);
88. conn.setDoOutput(true);
89. OutputStream os = conn.getOutputStream();
90. os.write(paramStr.toString().getBytes("utf-8"));
91. os.close();
92.
93. BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream()));
94. String line ;
95. String result ="";
96. while( (line =br.readLine()) != null ){
97. result += "\n"+line;
98. }
99. System.out.println(result);
100. br.close();
101.
102. }
103.
104. public static void doDelete(String urlStr,Map<String,Object> paramMap) throws Exception{
105. String paramStr = prepareParam(paramMap);
106. if(paramStr == null || paramStr.trim().length()<1){
107.
108. }else{
109. urlStr +="?"+paramStr;
110. }
111. System.out.println(urlStr);
112. URL url = new URL(urlStr);
113. HttpURLConnection conn = (HttpURLConnection)url.openConnection();
114. conn.setDoOutput(true);
115. conn.setRequestMethod(SERVLET_DELETE);
116. //屏蔽掉的代码是错误的,java.net.ProtocolException: HTTP method DELETE doesn't support output
117. /* OutputStream os = conn.getOutputStream();
118. os.write(paramStr.toString().getBytes("utf-8"));
119. os.close(); */
120.
121. if(conn.getResponseCode() ==200){
122. System.out.println("成功");
123. }else{
124. System.out.println(conn.getResponseCode());
125. }
126. }
127.
128. public static void main(String[] args) throws Exception{
129. String urlStr = "http://localhost:8080/SwTest/ReceiveDataServlet";
130. Map<String,Object> map = new HashMap<String,Object>();
131. map.put("username","张三");
132. map.put("password","88888");
133. // URLConnectionUtil.doGet(urlStr, map);
134. // URLConnectionUtil.doPost(urlStr, map);
135. // URLConnectionUtil.doPut(urlStr, map);
136. URLConnectionUtil.doDelete(urlStr, map);
137.
138. }
139.
140.
141. }
下面是一个例子:
1. package com.sw.study.urlConnection;
2.
3. import java.io.BufferedReader;
4. import java.io.InputStreamReader;
5. import java.io.OutputStream;
6. import java.net.HttpURLConnection;
7. import java.net.URL;
8. import java.net.URLConnection;
9. import java.util.HashMap;
10. import java.util.Map;
11.
12. public class URLConnectionUtil {
13.
14. private static final String SERVLET_POST = "POST" ;
15. private static final String SERVLET_GET = "GET" ;
16. private static final String SERVLET_DELETE = "DELETE" ;
17. private static final String SERVLET_PUT = "PUT" ;
18.
19. private static String prepareParam(Map<String,Object> paramMap){
20. StringBuffer sb = new StringBuffer();
21. if(paramMap.isEmpty()){
22. return "" ;
23. }else{
24. for(String key: paramMap.keySet()){
25. String value = (String)paramMap.get(key);
26. if(sb.length()<1){
27. sb.append(key).append("=").append(value);
28. }else{
29. sb.append("&").append(key).append("=").append(value);
30. }
31. }
32. return sb.toString();
33. }
34. }
35.
36. public static void doPost(String urlStr,Map<String,Object> paramMap ) throws Exception{
37. URL url = new URL(urlStr);
38. HttpURLConnection conn = (HttpURLConnection)url.openConnection();
39. conn.setRequestMethod(SERVLET_POST);
40. String paramStr = prepareParam(paramMap);
41. conn.setDoInput(true);
42. conn.setDoOutput(true);
43. OutputStream os = conn.getOutputStream();
44. os.write(paramStr.toString().getBytes("utf-8"));
45. os.close();
46.
47. BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream()));
48. String line ;
49. String result ="";
50. while( (line =br.readLine()) != null ){
51. result += "\n"+line;
52. }
53. System.out.println(result);
54. br.close();
55.
56. }
57.
58. public static void doGet(String urlStr,Map<String,Object> paramMap ) throws Exception{
59. String paramStr = prepareParam(paramMap);
60. if(paramStr == null || paramStr.trim().length()<1){
61.
62. }else{
63. urlStr +="?"+paramStr;
64. }
65. System.out.println(urlStr);
66. URL url = new URL(urlStr);
67. HttpURLConnection conn = (HttpURLConnection)url.openConnection();
68. conn.setRequestMethod(SERVLET_PUT);
69. conn.setRequestProperty("Content-Type","text/html; charset=UTF-8");
70.
71. conn.connect();
72. BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream()));
73. String line ;
74. String result ="";
75. while( (line =br.readLine()) != null ){
76. result += "\n"+line;
77. }
78. System.out.println(result);
79. br.close();
80. }
81.
82. public static void doPut(String urlStr,Map<String,Object> paramMap) throws Exception{
83. URL url = new URL(urlStr);
84. HttpURLConnection conn = (HttpURLConnection)url.openConnection();
85. conn.setRequestMethod(SERVLET_PUT);
86. String paramStr = prepareParam(paramMap);
87. conn.setDoInput(true);
88. conn.setDoOutput(true);
89. OutputStream os = conn.getOutputStream();
90. os.write(paramStr.toString().getBytes("utf-8"));
91. os.close();
92.
93. BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream()));
94. String line ;
95. String result ="";
96. while( (line =br.readLine()) != null ){
97. result += "\n"+line;
98. }
99. System.out.println(result);
100. br.close();
101.
102. }
103.
104. public static void doDelete(String urlStr,Map<String,Object> paramMap) throws Exception{
105. String paramStr = prepareParam(paramMap);
106. if(paramStr == null || paramStr.trim().length()<1){
107.
108. }else{
109. urlStr +="?"+paramStr;
110. }
111. System.out.println(urlStr);
112. URL url = new URL(urlStr);
113. HttpURLConnection conn = (HttpURLConnection)url.openConnection();
114. conn.setDoOutput(true);
115. conn.setRequestMethod(SERVLET_DELETE);
116. //屏蔽掉的代码是错误的,java.net.ProtocolException: HTTP method DELETE doesn't support output
117. /* OutputStream os = conn.getOutputStream();
118. os.write(paramStr.toString().getBytes("utf-8"));
119. os.close(); */
120.
121. if(conn.getResponseCode() ==200){
122. System.out.println("成功");
123. }else{
124. System.out.println(conn.getResponseCode());
125. }
126. }
127.
128. public static void main(String[] args) throws Exception{
129. String urlStr = "http://localhost:8080/SwTest/ReceiveDataServlet";
130. Map<String,Object> map = new HashMap<String,Object>();
131. map.put("username","张三");
132. map.put("password","88888");
133. // URLConnectionUtil.doGet(urlStr, map);
134. // URLConnectionUtil.doPost(urlStr, map);
135. // URLConnectionUtil.doPut(urlStr, map);
136. URLConnectionUtil.doDelete(urlStr, map);
137.
138. }
139.
140.
141. }
追问
大哥,下次别再这样回答问题了,好吗?
追答
你仔细研究一下程序没??这娃真笨。。
展开全部
那继续先把String 保存到文件或数据库下,jsp在去读取就行了
追问
你理解错了,java的cs小程序和ie浏览器jsp页面中间是没有牵涉到数据库的。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
先将String值 request.setAttribute(),再从界面得到
追问
因为web系统是买过来的,供应商不提供代码。所以jsp页面里面不能修改
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
调win32API 获取句柄 赋值
追问
java 没有实现,最终还是通过C#实现了。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
找一下response对象的使用方法
追问
唉,无语。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询