Development experience based on J2EE

Source: Internet
Author: User
Tags error handling

1. CMP's findByPrimaryKey sometimes returns NULL:
If a key value that does not exist in the database is sent to findByPrimaryKey, an exception is thrown.
If the parameter is a keyword in the database, the corresponding primarykey is returned.
2. For BMP, a create method must be called Remotely. Otherwise, JDBC may occur only once. If this create () statement is not used to return an object, you can write a value that returns the primayKey.
3. response. setContentType ("text/xml; charset = UTF-8 ");
PrintWriter out = response. getWriter ();
However, when encoding needs to be specified, the two statements must be in this order; otherwise, an error will occur.
Because the default encoding for response. getWriter () is ISO-5988-1, it is not transcoded into GB2312, UTF-8.
In addition, this encoding does not support Chinese characters.
4. For jsp pages, you can access them by link without configuring them in the web. xml file. Only for specific access needs
Configure it to the web. xml file to control the page direction.
5. For the error handling page, you only need to set the following in the web. xml file:
<Error-page>
<Error-code> 404 </error-code>
<Location>/error. jsp </location>
</Error-page>
That is, when a page access error occurs, the page is displayed. There is no way to handle errors in the request!
6. For jsp and servlet display and processing, garbled characters may often occur.
Usually
For jsp, <% @ page contentType = "text/html; charset = gb2312" %>
For servlets, Response. setContentType ("text/html; charset = gb2312 ");
Generally, it is an insurance method for displaying Chinese characters, and other codes may often contain garbled characters.
7. Sometimes the request content must be encoded. For example
Request. setCharacterEncoding ("GBK ");
8. Read files from the server database in the servlet (the fileupload component smartupload can be used for uploading). Example:
String SQL = "SELECT FileSize, FileStore FROM ResourseStore where MagazineNumber = '" + MIDValue + "'";
Stmt = con. prepareStatement (SQL );
ResultSet rs1_stmt.exe cuteQuery ();

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.