JSPservlet to receive garbled processing when receiving the Form table parameter

zhaozj2021-02-17  45

1. About JSP to receive the garbled code of the FORM parameter:

<% @ page contenttype = "text / html; charset = GB2312"%> <%! Public string getstr (string str) {string temp_p = str; byte [] temp_t = temp_p.getbytes ("ISO8859-1"); string temp = new string (TEMP_T); Return Temp;} Catch (Exception E) {} return "null";}%>

2. About the servlet to receive garbled with the FORM parameter.

File name: Threeparams.java content is as follows: package moreeservlets;

Import java.io. *;

Import javax.servlet. *;

Import javax.servlet.http. *;

Public Class ThreeParams Extends Httpservlet

{

/ / Define a function getStr () to solve the problem of garbled code

Public string getstr (string str) {

Try {string temp_p = STR;

BYTE [] TEMP_T = Temp_p.getbytes ("ISO8859-1");

String temp = new string (temp_t);

Return Temp;

}

Catch (Exception E) {}

Return "NULL";

}

// - Receive three parameters from FORM and display. Note that the third parameter has no conversion, which can be used to compare.

Public void doget (httpservletRequest Request,

Httpservletresponse response

THROWS IOEXCEPTION, ServletException

{

Response.setContentType ("text / html; charSet = GB2312");

PrintWriter out = response.getwriter ();

String DOCTYPE =

"

"Transitional // en /"> / n ";

Out.println (DOCTYPE

" / n"

" / n"

GetStr (Request.GetParameter ("param1")) "
"

GetStr (Request.GetParameter ("param2")) "
"

Request.GetParameter ("param3") "
"

"

Hello, Java world !! I am a servlet server applet !! / n" " ");

}

}

3. How to handle the problem with Chinese garbled when using JCONNECT connection Sybase database:

Make sure the database uses Chinese character sets, such as Eucgb, UTF8, CP936, and setting the necessary connection properties when JConnect programming, including Charset (requiring a database) and jConnect_version. For example: JConnect 4.2: JDBC: Sybase: TDS: Hostname: Port / DBNAME? Charset = Eucgb & jconnect_version = 4 JCONNECT 5.2: JDBC: Sybase: TDS: Hostname: Port / DBNAME? CHARSET = Eucgb & jconnect_version = 0

转载请注明原文地址:https://www.9cbs.com/read-28605.html

New Post(0)