Some experiences based on the development of Java EE

Source: Internet
Author: User
J2ee

The findbyprimarykey of 1.CMP will sometimes return null:
Send Findbyprimarykey A key value that does not exist in the database and throws an exception
If the parameter is a keyword that exists in the database, it returns the corresponding PrimaryKey
2. For BMP, you must call a Create method remotely, otherwise you can only be used once, and there will be a problem with JDBC. This create () if not with the return object, you can write any return primaykey value
3.response.setcontenttype ("Text/xml;charset=utf-8");
PrintWriter out = Response.getwriter ();
However, when encoding is required, these two statements must be in this order, otherwise there will be an error.
Because the default encoding for Response.getwriter () is iso-5988-1, it cannot be turned into gb2312,utf-8.
And this encoding does not support the Chinese language. 4. For JSP pages, usually do not need to be configured in the Web.xml file, you can access it according to the link. It is only necessary for a specific access
Configure to the Web.xml file to control the direction of the page.
5. For error-handling pages, simply 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 make a mistake about the request!
6. For the JSP and the servlet display and processing, often may appear garbled.
Usually
For JSPs, there are <%@ page contenttype= "text/html;charset=gb2312"%>
For servlet, there is Response.setcontenttype ("text/html;charset=gb2312");
Generally for the display, the Chinese above is the insurance method, some other code will often out of garbled
7. It is sometimes necessary to encode the content of the request. Such as
Request.setcharacterencoding ("GBK");
8. Read the file from the server's database in the servlet (upload can use the FileUpload Component Smartupload component). Example:
String sql= "Select Filesize,filestore from Resoursestore where magazinenumber= '" +midvalue+ "";
Stmt=con.preparestatement (SQL);
ResultSet Rs=stmt.executequery ();
if (Rs.next ()) {
int Len=rs.getint ("FileSize");
InputStream in = Rs.getbinarystream ("Filestore");//For ResultSet, get the order of the values returned in the Select, or the database will be out of order.
byte b[]=new Byte[len];
while (true)
{
int Readlen=in.read (b);
if (readlen==-1)
{
Break
}
}
Response.setcontenttype ("Application/x-msdownload");
Servletoutputstream op = response.getoutputstream ();
Op.write (b,0,b.length);
Op.flush ();
Op.close ();

If the database supports CLOB or CLOB (SQL service does not support reading or URLs), you can use a different approach to solve the problem. such as: Read binary (as above), read the string, and then through the type conversion!



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.