Recently, there is such a requirement that a home page obtains the request parameters (Chinese) from the request, and there are two frames on the home page,
Each frame is embedded with a JSP. How can we pass the Chinese parameter values on the home page into the frame?
Encode Chinese characters into Unicode and pass them to the JSP in the frame. The JSP in the frame is decoded. The program list is as follows:
Index. jsp
========================================================== ======================================
<% @ Page contenttype = "text/html; charset = UTF-8" %>
<% @ Page import = "java.net. urlencoder" %>
<%
String flowname = request. getparameter ("flowname ");
%>
<HTML>
<Head>
<Title>
Business Materials
</Title>
</Head>
<Frameset rows = "70%, *" Cols = "*" framespacing = "1" frameborder = "yes" border = "0">
<Frame src = "assetlist. jsp? Flowname = <% = flowname %> "name =" topframe "frameborder =" 1 "scrolling =" Auto "noresize>
<Frame src = "#" name = "acceframe" scrolling = "Auto">
</Frameset>
</Html>
Assetlist. jsp
========================================================== ======================
<% @ Page contenttype = "text/html; charset = UTF-8" %>
<% @ Taglib uri = "/WEB-INF/struts-bean.tld" prefix = "Bean" %>
<% @ Taglib uri = "/WEB-INF/struts-html.tld" prefix = "html" %>
<% @ Taglib uri = "/WEB-INF/struts-logic.tld" prefix = "logic" %>
<% @ Page import = "com. Founder. OA. Common. utils" %>
<% @ Page import = "com. Founder. OA. uiframe. complexsearch. *" %>
<% @ Page import = "Gov. Police. Tech. wcminterface. *" %>
<% @ Page import = "Gov. Police. Tech. application. dataexchange. *" %>
<% @ Page import = "com. Founder. fdam. oaiinterface. *" %>
<% @ Page import = "com. Founder. OA. daminterfaceadapter. *" %>
<% @ Page import = "Java. util. *" %>
<% @ Page import = "Gov. Police. Tech. application. appdata. *" %>
<%
String cond = "flowname = '" + request. getparameter ("flowname") + "'";
// Out. println (Cond );
Httpsession sess = request. getsession ();
Int allpage = 0; // Number of pages
String pageno = request. getparameter ("pageno ");
// If pageno is null, the value is 1.
If (pageno = NULL ){
Pageno = "1 ";
Sess. setattribute ("flowname", Cond );
}
Else {
Cond = (string) sess. getattribute ("flowname ");
// Out. println (Cond );
}
Int P = integer. parseint (pageno); // current page
Arraylist Al = new arraylist ();
Int size = 0;
Try {
Daminterfaceapp dapp = new daminterfaceapp ();
Verify ver = new verify (dapp );
Ver. login ("admin", "admin ");
Queryassetext quext = queryassetext. getinstance (dapp );
String strqueryresult = "";
Try
{
Strqueryresult = quext. queryallassets (150, Cond, "", "", 0 );
}
Catch (exception QE)
{
System. Err. Print ("error: An error occurred while calling the Bosi query interface queryassetext. queryallassets. error message:" + QE. getmessage ());
}
// Parse the query result
// System. Out. println ("prompt: the query result is:" + strqueryresult );
Al = (arraylist) queryassetadapter. getqueryassets (strqueryresult );
Allpage = pageutil. getallpage (Al );
// Out. println (allpage );
Al = pageutil. getpageitems (Al, P );
Size = Al. Size ();
// Out. println (size );
}
Catch (exception e ){
E. printstacktrace ();
}
%>
<HTML>
<Head>
<Title>
Business Materials
</Title>
<Link href = "<% = request. getcontextpath () %>/CSS/csstop.css" rel = "stylesheet" type = "text/CSS">
<Link href = "<% = request. getcontextpath () %>/CSS/link_sty.css" rel = "stylesheet" type = "text/CSS">
<Script language = "JavaScript">
VaR SWD = NULL;
Function selected (t)
{
If (SWD! = NULL)
SWD. classname = "";
If (t = SWD)
{
SWD = NULL;
Return;
}
T. classname = "xz ";
SWD = T;
Submit ();
}
Function submit ()
{
Document. frmassets. assetid. value = SWD. ID;
Document. frmassets. Submit ();
}
</SCRIPT>
<Style>
# Table1 tr {cursor: hand ;}
. Xz {color: # ffffff; Background-color: #66 CCCC ;}
</Style>
</Head>
<Body bgcolor = "# ffffff">
<Center> business related materials
<Form action = "accessory. jsp" name = "frmassets" target = "acceframe" method = "Post">
<Table id = "Table1" width = "90%" border = "1" align = "center" cellpadding = "2" cellspacing = "3">
<Tbody>
<Tr class = "gray">
<TD align = "center"> title
</TD>
<TD align = "center"> business name
</TD>
<TD align = "center"> Office
</TD>
<TD align = "center"> contact
</TD>
<TD align = "center"> contact number
</TD>
<TD align = "center"> Version
</TD>
</Tr>
<%
For (Int J = 0; j <size; j ++ ){
%>
<Tr id = "<% = (string) (MAP) Al. get (j )). get (new string ("ID") %> "onclick =" selected (this) ">
<TD align = "center"> <% = pageutil. getstr (string) (MAP) Al. Get (j). Get ("title") %>
</TD>
<TD align = "center"> <% = pageutil. getstr (string) (MAP) Al. Get (j). Get ("flowname") %>
</TD>
<TD align = "center"> <% = pageutil. getstr (string) (MAP) Al. Get (j). Get ("unit") %>
</TD>
<TD align = "center"> <% = pageutil. getstr (string) (MAP) Al. Get (j). Get ("linkman") %>
</TD>
<TD align = "center"> <% = pageutil. getstr (string) (MAP) Al. Get (j). Get ("linktel") %>
</TD>
<TD align = "center"> <% = pageutil. getstr (string) (MAP) Al. Get (j). Get ("version") %>
</TD>
</Tr>
<% }%>
</Tbody>
</Table>
<Br/>
Total <% = allpage %> pages
<A href = "assetlist. jsp? Pageno = 1 "> homepage </a>
<%
Int II = 0;
If (p> 1 ){
II = p-1;
}
%>
<A href = "assetlist. jsp? Pageno = <% = II %> "> previous page </a>
<%
If (P <allpage ){
II = p + 1;
}
Else if (P = allpage ){
II = P;
}
%>
<A href = "assetlist. jsp? Pageno = <% = II %> "> next page </a>
<A href = "assetlist. jsp? Pageno = <% = allpage %> "> last page </a>
<Input type = "hidden" name = "assetid">
</Form>
</Center>
</Body>
</Html>
Java program escape. Java for encoding and decoding
========================================================== ======================================
Package gov. Police. Tech. application. appdata;
Public class escape {
Private Final Static string [] hex = {"00", "01", "02", "03", "04", "05 ",
"06", "07", "08", "09", "0a", "0b", "0C", "0d", "0e", "0f ", "10 ",
"11", "12", "13", "14", "15", "16", "17", "18", "19", "1A ", "1B ",
"1C", "1D", "1E", "1f", "20", "21", "22", "23", "24", "25 ", "26 ",
"27", "28", "29", "2a", "2B", "2C", "2D", "2e", "2f", "30 ", "31 ",
"32", "33", "34", "35", "36", "37", "38", "39", "3A", "3B ", "3C ",
"3D", "3e", "3f", "40", "41", "42", "43", "44", "45", "46 ", "47 ",
"48", "49", "4A", "4B", "4C", "4D", "4E", "4f", "50", "51 ", "52 ",
"53", "54", "55", "56", "57", "58", "59", "5A", "5B", "5c ", "5d ",
"5E", "5f", "60", "61", "62", "63", "64", "65", "66", "67 ", "68 ",
"69", "6a", "6B", "6C", "6D", "6e", "6f", "70", "71", "72 ", "73 ",
"74", "75", "76", "77", "78", "79", "7A", "7b", "7C", "7D ", "7E ",
"7f", "80", "81", "82", "83", "84", "85", "86", "87", "88 ", "89 ",
"8a", "8b", "8C", "8d", "8e", "8f", "90", "91", "92", "93 ", "94 ",
"95", "96", "97", "98", "99", "9A", "9B", "9C", "9d", "9e ", "9f ",
"A0", "A1", "A2", "A3", "A4", "A5", "A6", "A7", "A8", "A9 ", "AA ",
"AB", "AC", "ad", "AE", "af", "B0", "B1", "B2", "B3", "B4 ", "B5 ",
"B6", "B7", "B8", "B9", "ba", "BB", "BC", "BD", "be", "BF ", "C0 ",
"C1", "C2", "C3", "C4", "C5", "C6", "C7", "C8", "C9", "ca ", "CB ",
"Cc", "cd", "CE", "CF", "D0", "d1", "D2", "D3", "D4", "D5 ", "D6 ",
"D7", "D8", "D9", "da", "DB", "DC", "DD", "de", "DF", "E0 ", "E1 ",
"E2", "E3", "E4", "E5", "E6", "E7", "E8", "E9", "EA", "Eb ", "EC ",
"Ed", "ee", "Ef", "F0", "f1", "F2", "F3", "F4", "F5", "F6 ", "F7 ",
"F8", "F9", "Fa", "FB", "FC", "FD", "Fe", "FF "};
Private Final Static byte [] val = {0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f,
0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f,
0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f,
0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f,
0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x00, 0x01,
0x02, 0x03, 0x04, 0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, 0x3f,
0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f,
0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f,
0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f };
/**
* Encoding
*
* @ Param s
* @ Return
*/
Public static string escape (string s ){
Stringbuffer sbuf = new stringbuffer ();
Int Len = S. Length ();
For (INT I = 0; I <Len; I ++ ){
Int CH = S. charat (I );
If ('A' <= CH & Ch <= 'Z') {// 'A' .. 'Z': as it was
Sbuf. append (char) CH );
} Else if ('A' <= CH & Ch <= 'Z') {// 'A' .. 'Z': as it was
Sbuf. append (char) CH );
} Else if ('0' <= CH & Ch <= '9') {// '0' .. '9': as it was
Sbuf. append (char) CH );
} Else if (CH = '-' | CH = '_' // unreserved: as it was
| CH = '.' | CH = '! '| CH = '~ '| CH = '*'
| CH = '/''| CH =' ('| CH = ')'){
Sbuf. append (char) CH );
} Else if (CH <= 0x007f) {// other ASCII: map to % xx
Sbuf. append ('% ');
Sbuf. append (hex [CH]);
} Else {// UNICODE: map to % uxxxx
Sbuf. append ('% ');
Sbuf. append ('U ');
Sbuf. append (hex [(CH >>> 8)]);
Sbuf. append (hex [(0x00ff & Ch)]);
}
}
Return sbuf. tostring ();
}
/**
* Decoding Description: This method ensures that the correct "decoding" result is obtained no matter whether the parameter S is encoded by escape ().
*
* @ Param s
* @ Return
*/
Public static string Unescape (string s ){
Stringbuffer sbuf = new stringbuffer ();
Int I = 0;
Int Len = S. Length ();
While (I <Len ){
Int CH = S. charat (I );
If ('A' <= CH & Ch <= 'Z') {// 'A' .. 'Z': as it was
Sbuf. append (char) CH );
} Else if ('A' <= CH & Ch <= 'Z') {// 'A' .. 'Z': as it was
Sbuf. append (char) CH );
} Else if ('0' <= CH & Ch <= '9') {// '0' .. '9': as it was
Sbuf. append (char) CH );
} Else if (CH = '-' | CH = '_' // unreserved: as it was
| CH = '.' | CH = '! '| CH = '~ '| CH = '*'
| CH = '/''| CH =' ('| CH = ')'){
Sbuf. append (char) CH );
} Else if (CH = '% '){
Int CINT = 0;
If ('U '! = S. charat (I + 1) {// % XX: map to ASCII (XX)
CINT = (CINT <4) | Val [S. charat (I + 1)];
CINT = (CINT <4) | Val [S. charat (I + 2)];
I + = 2;
} Else {// % uxxxx: map to Unicode (XXXX)
CINT = (CINT <4) | Val [S. charat (I + 2)];
CINT = (CINT <4) | Val [S. charat (I + 3)];
CINT = (CINT <4) | Val [S. charat (I + 4)];
CINT = (CINT <4) | Val [S. charat (I + 5)];
I + = 5;
}
Sbuf. append (char) CINT );
} Else {// The character is not encoded
Sbuf. append (char) CH );
}
I ++;
}
Return sbuf. tostring ();
}
Public static void main (string [] ARGs ){
String stest = "Chinese 1234 ABCD [] () <+> ,.~ //";
System. Out. println (stest );
System. Out. println (escape (stest ));
System. Out. println (Unescape (escape (stest )));
}
}