Ajax in the process of developing the data acquisition problems hash

  Ajax in the process of developing the data acquisition problems hash 

  I continue to this day in the Ajax trip.    Has been stepping up the pace. 

  The day before trial to form Ajax form to the server, access to information content in the form of gibberish, 1:00 insurmountable.    Have concluded that the Internet is application / x-www-form-urlencoded coding reasons, I also estimated.    Are looking for a solution. 

  Members discussed the discussion. 

  2005-12-05 11:20 added: 
  In the background by using UTF8 yards to the way the problem can be solved Chinese gibberish.    This approach to the form against form, completed in the server code.    Code as follows: 
  Form.jsp: 
  <% @ Page contentType = "text / html; gb2312 charset ="%> 
<html>
<head>
  <meta Http-equiv="Content-Type" content="text/html; charset=gb2312"> 
  <title> Form to the test </ title> 
  <script Language="javascript"> 
  Var http_request = false; 
  Function send_request (url, poststr) (/ / initialization, the designated processing function, a function of the request sent 
  Http_request = false; 
  / / Initialization started XMLHttpRequest object 
  If (window.XMLHttpRequest) (/ / Mozilla browser 
  Http_request = new XMLHttpRequest (); 
  If (http_request.overrideMimeType) (/ / Set MiME category 
  Http_request.overrideMimeType ( 'text / xml'); 
  ) 
  ) 
  Else if (window.ActiveXObject) (/ / IE browser 
  Try ( 
  Http_request = new ActiveXObject ( "Msxml2.XMLHTTP"); 
  ) Catch (e) ( 
  Try ( 
  Http_request = new ActiveXObject ( "Microsoft.XMLHTTP"); 
  ) Catch (e) () 
  ) 
  ) 
  If (! Http_request) (/ / anomaly, the failure to create instances 
  Window.alert ( "can not create XMLHttpRequest object instance."); 
  Return false; 
  ) 
  Http_request.onreadystatechange = processRequest; 
  / / Determine the modalities and sent the request URL and the simultaneous implementation of the code 
  Http_request.open ( "POST", url, true); 
  Http_request.setRequestHeader ( "Content-Type", "application / x-www-form-urlencoded"); 
  Http_request.send (poststr); 
  ) 
  / / Return information processing function 
  Function processRequest () ( 
  If (http_request.readyState == 4) (/ / Object state judge 
  If (http_request.status == 200) (/ / information has been successfully returned to start processing information 
  Alert (http_request.responseText); 
  ) Else (/ / pages is not normal 
  Alert ( "You have an unusual request pages."); 
  ) 
  ) 
  ) 
  Function form_submit () ( 
  Var f = document.form1; 
  Var username = f.username.value; 
  Var password = f.password.value; 
  Var poststr = ""; 
  If (username =="") ( 
  Window.alert ( "ID can not be empty."); 
  F.username.focus (); 
  Return false; 
  ) 
  If (password =="") ( 
  Window.alert ( "password can not be empty."); 
  F.password.focus (); 
  Return false; 
  ) 
  Poststr = "username =" + encodeURI (f.username.value) + "& password =" + f.password.value; 
  Send_request ( 'form_handle.jsp' poststr); 
  Return false; 
  ) 
  </ Script> 
  </ Head> 

<body>
  <form Name="form1" method="post" action="" onsubmit="return form_submit()"> 
  <table Width="300" border="0" cellspacing="4" cellpadding="0" style=" font-size:12pt;"> 
<tr>
  <td Width="74" height="25"> ID: </ td> 
  <td Width="220" height="25"> <input name="username" type="text" id="username" size="20"> </ td> 
  </ Tr> 
<tr>
  <td Height="25"> Password: </ td> 
  <td Height="25"> <input name="password" type="password" id="password" size="20"> </ td> 
  </ Tr> 
  <tr Align="center"> 
  <td Height="25" colspan="2"> <input type="submit" name="Submit" value="提交"> </ td> 
  </ Tr> 
  </ Table> 
  </ Form> 
  </ Body> 
  </ Html> 

  Form_handle.jsp: 
  <% @ Page contentType = "text / html; charset = gb2312" language = "java" errorPage = ""%> 
<%
  String username = new String (request.getParameter ( "username"). GetBytes ( "ISO-8859-1"), "UTF8"); 
  String password = request.getParameter ( "password"); 
  System.out.println ( "ID:" + username); 
  System.out.println ( "Password:" + password); 
  Out.println (+"|"+ username password); 
%>

  Moreover, some Chinese netizens include the reaction of the contents of XML documents will be returned to the client in question hash.    XML document proposes to change UTF8 encoding try. 

  We look forward to the feedback. 

  Posted on 2005-12-05 10:50 eamoi reading (8727) Comments (28) edit their collections quoted Categories: AJAX 
  Comments: # re: Ajax in the process of developing the data acquisition problems hash 2005-12-06 17:53 | emu 
 
Old problems, the simplest way is to send all escape after.    Recover after unescape absolutely no coding problems.    If you need the server-side escape / unescape can see 
 
Http://www.blogjava.net/emu/articles/4773.html 
 
This is the original intention of posting xml to solve the problem.    Competition in East Asia last google also has a similar examination of the subject, I direct copy of the code from the top of the pay boost huh.    If other background to their own written language. 

  If GBK background encoded with UTF-8 with prospects, you can direct backstage code, if in the future we should use to vbscript code: 
 
<SCRIPT LANGUAGE="vbScript"> 
 
<! – 
 
Function URLEncoding (vstrIn) 
 
StrReturn = "" 
 
For i = 1 To Len (vstrIn) 
 
ThisChr = Mid (vStrIn, i, 1) 
 
If Abs (Asc (ThisChr)) <& HFF Then 
 
StrReturn = strReturn & ThisChr 
 
Else 
 
InnerCode = Asc (ThisChr) 
 
If innerCode <0 Then 
 
InnerCode innerCode + = & H10000 
 
End If 
 
Hight8 = (innerCode And & HFF00) \ & HFF 
 
InnerCode And Low8 = & HFF 
 
StrReturn strReturn & = "%" & Hex (Hight8) & "%" & Hex (Low8) 
 
End If 
 
Next 
 
URLEncoding = strReturn 
 
End Function 
 
//–> 
 
</ SCRIPT> 

  After sending out such code, the background can be encoded by gbk received. 

  Reply comments more 
 
# Re: Ajax in the process of developing the data acquisition hash issues 2005-12-13 20:20 | Guoxinghua Hello: I consult your question to: 
 
I would like to make student information management system!! 
 
On the website in the name of entry, I would like to a "google suggest" the effect of that entry "Zhang", can occur immediately following a "layer", its name will be all the surname "Zhang" the show. 
 
One of the main functions I have achieved. Mainly with the following knowledge: 
 
Ajax not to a page can be updated data. Use httprequest.open ( "GET ","***. xml", true) 
 
Adoption of return xml document, then use the getElementsByTagName analytical xml documents. 

  But now I question is that I have the server-side all students information stored in *. mdb (mdb and I intend to use, because I feel I am more comfortable in), I would like to clients under the name text box entry's surname, Send requests to the server-side. could be achieved: 
 
The use of post sent a request. Open ( "POST ",****? surname, true) 
 
2 server can "name" from the mdb database server found in all the surname "Zhang" to the 
 
All three will be "Zhang" generation-such as the names of <name> San </ xml document the name >…. 

  So I ask you: 
 
Like how a server-side xmldoc documents can be generated, and then transform (xmldoc) passed client. Httpresponse.responseXML client can be used to return data, reuse getElementByTagName to parse. 
 
2 Can you tell me how the server-side procedures written?? 
 
3 Can you tell me what the use of server-side technologies?    ?    Java2.0 need?    Tomcat?    Servlet? 
 
3 machines is my winxp IIS, I also need to install the machines?    ?   

  Teachers look forward to the advice!    !    !   

  Reply comments more 
 
# Re: Ajax in the process of developing the data acquisition problems 2005-12-14 hash 9:28 | eamoi 
 
Answered as follows: 
 
1, returned to the server-side XML: 
 
Use post Send requests. Open ( "POST ",****? surname, true) is a feasible solution.    Open the URL can be a variety of background processes, such as ASP, JSP, etc..    URL address format **. asp? Surname =…    Only in the background at the open files, it is necessary to output xml documents.    For example, ASP, using a print Response.write XML documents; out.pringln used in the JSP print out an XML document.    AJAX will automatically return.    Return to the client, by JS DOM manipulation can be updated on the content pages.    This process has nothing to do with the database type, simply remove the data is a process only. 

  2, how to write server-side code: 
 
According to your use of technology to a GOOGLE search, keyword "** generate XML documents."    For example: "JSP generate XML documents."    View should be able to generate XML documents methods.    I do not repeat this point the. 

  3, the technical needs of the server-side: 
 
Ajax is only a view of improving and enhancing the efficiency of data exchange methods only, in theory, almost all of the applicable procedures for the background, at least for now has support JSP / ASP / .NET / CGI, I think you should be on the programming is not the issue. 

  4, with IIS also need to install the machine what: 
 
IIS server application, background procedures should be adopted or ASP. NET bar.    Ajax need is a plug-in technology, it will only present several technical Javascript, XML and XSTL, DOM, XMLHttpRequest integrated with the use of these technologies have been mainstream Web server and browser support, needless worry.    So conclusion is: no need to install additional software or plug-in the. 

  Finally, I wish smoothly.    Reply comments more 
 
# Re: Ajax in the process of developing the data acquisition hash issues 2005-12-14 09:32 | eamoi 
 
I would like a "google suggest" the effect of that entry "Zhang", can occur immediately following a "layer", its name will be all the surname "Zhang" the show. 
 
~~~~~~~~~~~~~ This data is automatically match should function.    Should not be difficult to achieve.    Several mainstream in the Ajax box Jianzhong can see that this has been supported, such as Ajax JSP Tag Library.    Reply comments more 
 
# Re: Ajax in the process of developing the data acquisition hash issues 2005-12-14 11:52 | Guoxinghua Hello: 

  You write that the above examples. I copied down form.jsp form_handle.jsp intact copy down. How debugging of "the page you have requested an unusual" 
 
My other machine is not installed winxp iis. (Tomcat java2sdk have not installed)? What is the reason? Back more comments 
 
# Re: Ajax in the process of developing the data acquisition hash issues 2005-12-14 12:16 | Guoxinghua you can to: www.javascript.com.cn Forum under the "Ajax (javascript, XMLHttpRequest, DOM … …) "look at the forum under the theme" Ajax2 "that the word affixed to the answer to?? 
 
That there is also your book?! Back more comments 
 
# Re: Ajax in the process of developing the data acquisition hash issues 2005-12-15 21:57 | llinzzi 
 
Answer Guoxinghua friends 
 
Jsp is in need of services-running environment, install tomcat. Restore more comments 
 
# Re: Ajax in the process of developing the data acquisition hash issues 2005-12-17 13:13 | Guoxinghua clearance operation xml dom use stem the problem: 
 
I JBuild4.0 (tomcat5.0) has C: \ Tomcat 5.0 \ common \ endorsed \ xml-apis.jar into, and then prepare document1.java 

  Package com.deitel.advjhtp1.servlets; 
 
Import javax.xml.parsers .*; 
 
Import javax.xml.transform .*; 

  Import javax.xml.parsers.DocumentBuilderFactory; 
 
Import javax.xml.parsers.DocumentBuilder; 

  Import javax.xml.transform.dom .*; 
 
Import javax.xml.parsers .*; 

  (Public class document1 

  Public document1 () ( 
 
Document doc; 
 
Document doc1 = DocumentBuilderFactory.newInstance (). NewDocumentBuilder (). NewDocument (); 
 
DOMSource doms = new DOMSoruce (doc); 
 

 

  Compile-time following error: 

  [Document doc; the mistakes in this statement:] 

  "Document1.java": Error #: 300: class Document not found in class com.deitel.advjhtp1.servlets.document1 at line 15, column 3 

  [This statement: Document doc1 = DocumentBuilderFactory.newInstance (). NewDocumentBuilder (). NewDocument (); the following two mistakes] 

  "Document1.java": Error #: 300: class Document not found in class com.deitel.advjhtp1.servlets.document1 at line 16, column 3 
 
"Document1.java": Error #: 360: unreported exception: javax.xml.parsers.ParserConfigurationException; must be caught or declared to be thrown at line 16, column 72 

  [DOMSource doms = new DOMSoruce (doc); this sentence appears the following error:] 

  "Document1.java": Error #: 300: class DOMSoruce not found in class com.deitel.advjhtp1.servlets.document1 at line 17, column 22 

  Please expert advice! Back more comments 
 
# Re: Ajax in the process of developing the data acquisition hash issues 2005-12-17 14:12 | Guoxinghua 
 
Import javax.xml.transform.dom.DOMSource; 
 
Import javax.swing.text.Document; 
 
With the above two sentences that document doc; not wrong, exactly the same as the other. Restore more comments 
 
# Re: Ajax in the process of developing the data acquisition problems hash 2005-12-18 13:25 | Guoxinghua 
 
Package com.deitel.advjhtp1.servlets; 
 
Import org.w3c.dom .*; 
 
Import javax.xml.parsers .*; 
 
Import org.xml.sax .*; 

  (Public class WelcomeServlet2 

  Public WelcomeServlet2 () ( 
 

 
Public static void main (String [] args) ( 

  Document doc; 
 
Element root; 
 
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance (); 
 
Factory.setValidating (true); 
 
Try ( 
 
DocumentBuilder builder = factory.newDocumentBuilder (); 
 
Doc = builder.newDocument (); 
 
) Catch (ParserConfigurationException pce) 
 

 
Pce.printStackTrace (); 
 

  Root = doc.createElement (the "result"); 

 
 

  Or Tip: root = doc.createElement (the "result"); this remark wrong 
 
"WelcomeServlet2.java": Error #: 553: variable doc might not have been initialized at line 24, column 10 
 
Netease original posts from the community: http://p5.club.163.com/viewArticleByWWW.m?boardId=java&articleId=java_107a8e37bc7341e back more comments 
 
# Re: Ajax in the process of developing the data acquisition problems 2005-12-25 hash 8:29 | Guoxinghua use jdbc.odbc visit Access database. Mdb, wrote how Class.for (), 
 
Branded class. When behind in the tips do not show for it, experts advise!   

  Using the Jbuilder4.0, 
 
My system is jbuilder4.0 I have added 
 
Import java.sql .*; 
 
Import java.lang.class .*; 

  I suspect that is not what I am. Jar config jdk not? 
 
Please expert advice! Back more comments 
 
# Re: Ajax in the process of developing the data acquisition problems hash 2006-01-11 18:09 | cream in the asp resolve hash problems in the server side need only add <% Response.ContentType = "text / html; charset = GB2312 "%> can be a very simple!    Reply comments more 
 
# Re: Ajax in the process of developing the data acquisition problems hash 2006-01-17 11:17 | suyejun 
 
I outlook pages using the GBK, why should the background but new String (req.getParameter ( "username"). GetBytes ( "ISO-8859-1"), "UTF-8") to the code?    I am not too clear about coding, can point to the comments, thank you ~ 
 
Ps: Your Guide to restore more I like the comment 
 
# Re: Ajax in the process of developing the data acquisition problems 2006-01-23 hash 5:48 | AJAX hash new solution can be used to escape () function of the ah. 

  Var url = "aaa.aspx? Value =" + escape (val); 
 
/ / I am. Under the Net found no problems, the value of database insertion no Chinese chaos? Comment on the issue back more 
 
# Re: Ajax in the process of developing the data acquisition problems hash 2006-02-07 12:29 | haiter 
 
I also encountered "data from the hash" 
 
I do not know how to solve? Back more comments 
 
# Re: Ajax in the process of developing the data acquisition problems hash 2006-02-15 21:41 | sea135 
 
I ajax the responseText receiver is garbled 

  Form_handle.jsp in 
 
Out.println (+"|"+ username password); output is UTF-8 string 
 
However: 
 
Out.println ( "incorrect password") 
 
This will not be received in the responseText is garbled? 

  Reply comments more 
 
# Re: Ajax in the process of developing the data acquisition problems hash 2006-02-15 21:50 | sea135 
 
I also somewhat different from the situation 
 
Before I call the request.setRequestEncode ( "GBK"); 
 
After the action I 
 
Out.print ( "success"); 
 
Then in the responseText receiver is garbled! 
 
I tried to convert a "successful" but useless string encoding 

  I hope that can help answer, be grateful restore more comments 
 
# Re: Ajax in the process of developing the data acquisition problems hash 2006-02-27 10:45 | javadolt 
 
I escape after-parameter to NULL the past, the past-not to escape the normal English, noon hash.    I was http_request.send (data); transmit data over the past. 
 
If directly behind the increase in the url? Test = Chinese, no problem, the ISO-8859-1 to GBK on it.    Reply comments more 
 
# Re: Ajax in the process of developing the data acquisition hash issues 2006-04-08 00:39 | errorfun 
 
Not used filters?    ?    Reply comments more 
 
# Re: Ajax in the process of developing the data acquisition problems 2006-04-26 hash 9:56 | HH 
 
JavaScript: 
 
AssertEquals ( "% E7% 84% 9A," encodeURI ( "")); 

  Java: 
 
AssertEquals ( "\ u7684", ""); 
 
AssertEquals ( "" URLDecoder.decode ( "% B5% C4", "GB2312")); 
 
AssertEquals ( "" URLDecoder.decode ( "% E7% 9A% 84", "UTF-8")); 

  Reference: Java Chinese hash issues Daquan 
 
Reply comments more 
 
# Re: Ajax in the process of developing the data acquisition problems hash 2006-05-18 6:56 | java in the 
 
Hh more detail what is the meaning of some okay?    Reply comments more 
 
# Re: Ajax in the process of developing the data acquisition problems 2006-06-25 hash 8:28 | betty 
 
@ Guoxinghua 
 
We should add import org.w3c.dom .*; 
 
Like yes.    Reply comments more 
 
# Re: Ajax in the process of developing the data acquisition hash issues 2006-06-29 15:31 | luchunwei 
 
Thank you, this is pretty good.    Reply comments more 
 
# Re: Ajax in the process of developing the data acquisition hash issues 2006-09-05 10:26 | fdsfds 
 
Thank you, 
 
String ss = new String (request.getParameter ( "value"). GetBytes ( "ISO-8859-1"), "UTF8"); 
 
System.err.println (ss); 
 
I find this is the first big problem be resolved.    Thank you, the too 
 
But like in the servlet: request.setCharacterEncoding ( "UTF8"); 
 
String ss = request.getParameter ( "value"); 
 
System.err.println ( "post pd:" + ss); 
 
On the trip.    Reply comments more 
 
# Re: Ajax in the process of developing the data acquisition hash issues 2006-09-06 15:32 | crows fly at night, in fact for all the problems of the lack of harmonization from coding: 
 
1, HTTP / POST way in default, use the "x-www-form-urlencoded" coding, it inside encodeURI JavaScript and the role played by the same; 
 
2, after the content of this code, at the background, one of the characters is UTF-8 encoding formats; 
 
3, if you Servlet / JSP output designated use of the Content-Type is UTF-8, congratulate you, you do not need these Parameters for special encoding, decoding, and it certainly is normal; 
 
4, otherwise, you need to carry out these parameter of the encoding operation, for example, your page is GBK coding, then you need to write: 
 
String sPara = new String (request.getParamter ( "test"). GetBytes ( "iso-8859-1"), "GBK"); 
 
Gb2312 coding used can also be used GBK coding; 
 
5, if you are in the eclipse of the work, please pay attention to your Servlet and JSP document attributes, including the coding and content-type must be installed in the same, otherwise you will javac document coding errors, this time the bytecode document itself is a string of errors, the output is the top; 
 
6, the last to do a summary: 
 
6.1, servlet / JSP document itself must be encoded and output content-type agreement, or else the need for additional encoding, decoding steps; 
 
6.2, HTTP / POST ways and means imported encodeURI coding are UTF-8; 
 
6.3, ordinary window.open (…), is HTTP / GET, its introduction and operation of the code is encoded script pages consistent; 
 
6.4 decoding must pass background iso-8859-1 decode and then use your goals coding coding; 
 
6.5, basically all the issues can be resolved.    Reply comments more 
 
# Re: Ajax in the process of developing the data acquisition hash issues 2007-05-31 14:40 | itblog 
 
I would like to ask eamoi teachers, the final solution, because I now faced the same problem! Thank you! Back more comments 
 
# Re: Ajax in the process of developing the data acquisition hash issues 2007-06-11 10:57 | purple.calm 
 
Do jsp have convert methods? Just like in php mb_convert_encoding () back more comments 
 
# Re: Ajax in the process of developing the data acquisition hash issues 2007-06-12 15:22 | wind ajax I use the language of the text from frame to submit to background values, the format of the entire text box has not only submitted pure data past, the round-trip that is not all, have encountered the same problem?, will comment on how to resolve back more 

Tags: , , ,

Releated Java Articles

Comments

Leave a Reply