Wap development in jsp

Source: Internet
Author: User

Solutions for Chinese in JSP:
After adding the following sentence, China Mobile can directly write Chinese characters on the page, without conversion. The submitted Chinese characters are directly obtained by request. getParameter (""), without conversion.
Java code
<% @ Page contentType = "text/vnd. wap. wml; charset = gb2312" %>
<% Response. setContentType ("text/vnd. wap. wml; charset = UTF-8"); %>
<% Request. setCharacterEncoding ("UTF-8"); %>
After China Unicom adds the following sentence, you can directly write Chinese characters on the page, without conversion. The submitted Chinese characters are directly obtained by request. getParameter (""), without conversion.
Java code
<% @ Page contentType = "text/vnd. wap. wml; charset = gb2312" %>
<% Request. setCharacterEncoding ("UTF-8"); %>

Operating System win2000, Web Server resin (or tomcat)
All found out in practice, and the business has been launched, no problem.

My solution:
(1) The wml file is defined:
Java code
<? Xml version = "1.0" encoding = "UTF-8"?>
(2) Transmit the submitted data using post
Java code
<Go href = "/wapapp/servlet_wap" method = "post">
<! -- Go href = "/servlet/wap86test" -->
<Postfield name = "serviceID" value = "0002"/>
<Postfield name = "phone" value = "$ (phone: e)"/>
<Postfield name = "passwd" value = "$ (passwd: e)"/>
</Go>
(3) Background Conversion
Move -->
Configure the doget and dopost methods in the servlet
Java code
Request. setCharacterEncoding ("UTF-8 ");
Response. setContentType (Const. CONTENT_TYPE); // Const. CONTENT_TYPE: text/vnd. wap. wml; charset = UTF-8

① Form for post submission and processing:
Generally, the request. getParameter ("xxx") is obtained in Chinese and no transcoding is required;
Add members
The post code for adding members is:
Java code
<Do type = "accept" label = "OK"> <go href = "/wapapp/servlet_wap" method = "post">
<Postfield name = "serviceID" value = "0207"/>
<Postfield name = "groupname" value = "scheduled launch point 222"/>
<Postfield name = "groupcode" value = "4"/>
<Postfield name = "aphone" value = "$ aphone"/>
<Postfield name = "aname" value = "$ (aname: e)"/>
</Go> </do>
In the program block with the processing number "0207", the obtained parameters are processed in this way.
Java code
String groupcode = request. getParameter ("groupcode ");
String groupName = request. getParameter ("groupname ");
String ctcPhone = request. getParameter ("aphone ");
String ctcName = request. getParameter ("aname ");
CtcName = ctcName. replaceAll ("","");
CtcName = ctcName. replaceAll ("","");

If (! UserType. equals (SysChinaMobile) {// If mobile is used, the getparameter is Chinese, but the UNICOM is not. Therefore, transcoding is required.
Java code
Try {
GroupName = WapUtil. decode (groupName, "UTF-8 ");
CtcName = WapUtil. decode (ctcName, "UTF-8 ");
} Catch (Exception e ){
E. printStackTrace (); // To change body of catch statement use File | Settings | File Templates.
Out. println (returnPrevPage (strErrosOnServerCallAdmin ));
}
}

② Url parameters submitted by get:
If you use the get method or url to pass parameters, you cannot use the decode method to implement transcoding, but use the togbk method;
In addition, if you print the wml page in the servlet, you can only use the togbk Method for code conversion;
For example, the homepage of group information is displayed.
The page url of the request to display the modification group is/wapapp/servlet_wap? ServiceID = 0212 & groupcode = 6 & groupname = % B0 % B4 % CA % B1 % B5 % C4 % B7 % A8333
In the program block with the processing number "0212", the obtained parameters are processed in this way.
Java code
String groupcode = request. getParameter ("groupcode ");
String groupname = request. getParameter ("groupname ");
Try {
Groupname = WapUtil. togbk (groupname );
Groupcode = WapUtil. togbk (groupcode );
} Catch (Exception e ){
E. printStackTrace (); // To change body of catch statement use File | Settings | File Templates.
Out. println (returnPrevPage (strErrosOnServerCallAdmin ));
}
China Unicom -->
Configure the doget and dopost methods in the servlet
Java code
Response. setContentType (Const. CONTENT_TYPE); // Const. CONTENT_TYPE: text/vnd. wap. wml; charset = UTF-8

① Form for post submission and processing:
Call the decode method for transcoding;
② Url parameters submitted by get:
You need to call the togbk Method for transcoding.
The most important methods in Waputil are as follows:
WapUtil. toUrl (String gbkStr): If a Chinese parameter exists, use this method for conversion.
WapUtil. gbk2unicode (String gbkStr): converts Chinese characters to UTF-8 characters and displays them on the page;
WapUtil. togbk (String Utfstr): converts utf text to gbk for background processing;
WapUtil. decode (String s, String encoding): Convert the text in the specified code format to gbk format for background processing;
1) wap multiple selection box
Java code
<Card id = "phones" title = "group information">
<Do type = "prev" name = "Prev" label = "Back">
<Go href = "meeting. wml"> </go> </do>
<Do type = "accept"> <go href = "servlet_wap? ServiceID = 0124 "type =" codeph "text =" codeph ">
<Postfield name = "scity" value = "1"/>
<Postfield name = "members" value = "$ members"/>
</Go> </do>
<P mode = "nowrap"> ** select a meeting Member **
<Select name = "members" multiple = "true">
<Option value = "138345657678"> 88 (138345657678) </option>
<Option value = "1383456576786"> 88886 (1383456576786) </option>
<Option onpick = "meeting. wml"> [Return] </option>
</Select>
</P>
</Card>

2) wap single-region
Java code
<Card>
<P> Please choice your favorite Web. <br/>
<Select name = "X">
<Option value = "S"> sina </option>
<Option value = "Y"> yahoo </option>
</Select>
<P>
</Card>

3) about the Left and Right soft buttons) (the menu is automatically resolved by the mobile browser, right-click the phone ;)
Java code
<Do type = ". options." label = "OK" optional = "false">
<Go href = "/wapapp/servlet_yxtwap? ServiceID = 0214 "type =" regxph "text =" yourobjectname "/>
</Do>

Represents the right soft button, a "OK" button;
Java code
<Do type = ". Accept." label = "return" optional = "false">
<Go href = "../servlet_yxtwap? ServiceID = 0201 "type =" regxph "text =" yourobjectname "/>
</Do>

Represents the left soft button, a "return" button;

It is best to do this:
Java code
<Do type = "options" name = "Prev" label = ""> <go href = "indexmember. wml"> </go> </do>
<Do type = "Accept" label = "OK">
<Go href = "/wapapp/servlet_yxtwap? ServiceID = 0401 "type =" codeph "text =" codeph ">
<Postfield name = "name" value = "$ name"/>
<Postfield name = "nick" value = "$ nick"/>
<Postfield name = "call" value = "$ call"/>
</Go>
</Do>

Return to the previous page:
Java code
<Do type = "options" name = "Prev" label = ""> <prev/> </do>
 
<Do type = "options" name = "Prev" label = ""> <go href = "index. wml"> </go> </do>
<Do type = "accept" label = "OK">
<Go href = "/wapapp/servlet_wap" method = "post">
<! -- Go href = "/servlet/wap86test" -->
<Postfield name = "serviceID" value = "0002"/>
<Postfield name = "phone" value = "$ (phone: e)"/>
<Postfield name = "passwd" value = "$ (passwd: e)"/>
</Go>
</Do>

Author "SILON"
 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.