There is no difference with Asp.net:
JSP
<% @ Page Language = "Java" contenttype = "text/html" pageencoding = "UTF-8" %>
<! Doctype HTML public "-// W3C // dtd html 4.01 transitional // en">
<HTML>
<Head>
<Title> my JSP 'index. jsp 'starting page </title>
<Meta http-equiv = "content" content = "text/html; charset = UTF-8">
<SCRIPT type = "text/JavaScript" src = "jquery-1.3.2.js"> </SCRIPT>
<SCRIPT type = "text/JavaScript">
Function Sub ()
{
$. Ajax ({
Type: "Post ",
URL: "loginservlet ",
Data :{
Username: $ ("# username"). Val (),
Content: $ ("# Content"). Val ()
},
Success: function (data, textstatus ){
$ ("# Restext" cmd.html (data );
}
});
}
</SCRIPT>
</Head>
<Body>
<Form action = "./test" id = "form1" method = "Post">
<P> </P>
<P> <input type = "text" name = "username" id = "username"/> </P>
<P> <textarea name = "content" id = "content" rows = "2" Cols = "20"> </textarea> </P>
<P> <input type = "button" id = "send" value = "" onclick = "sub ();"/> </P>
</Form>
<Div class = "comment">
</Div>
<Div id = "restext">
</Div>
</Body>
</Html>
Servlet
Package com;
Import java. Io. ioexception;
Import java. Io. printwriter;
Import javax. servlet. servletexception;
Import javax. servlet. http. httpservlet;
Import javax. servlet. http. httpservletrequest;
Import javax. servlet. http. httpservletresponse;
Public class test extends httpservlet {
Public void Service (httpservletrequest request, httpservletresponse response)
Throws servletexception, ioexception {
Request. setcharacterencoding ("UTF-8 ");
Response. setcontenttype ("text/html; charset = UTF-8 ");
System. Out. println ("start ............");
String username = request. getparameter ("username ");
String content = request. getparameter ("content ");
// Username = new string (username. getbytes ("gb2312"), "UTF-8 ");
Printwriter out = response. getwriter ();
Out. Write (username );
System. Out. println ("username >>=" + username );
Out. Write (content );
Out. Flush ();
Out. Close ();
System. Out. println ("end ");
}
}