10 problems encountered during work in: 1-10, 1-10 in

Source: Internet
Author: User

10 problems encountered during work in: 1-10, 1-10 in
1. NullPointerException.
If the content category contains dirty data and an error is reported, You need to determine whether the variable is Null.
Check the content. The id is invalid and the content cannot be found. You need to determine whether there is a value. If it is null, the page jumps to the 404 page.


2. An invalid file name appears during PDF download.
Linux and Windows have certain restrictions on the file name. It is forbidden to contain several characters in the file name.
When downloading PDF files, I use the title of the document as the file name. The title contains "invalid characters", such
"The cost of living for IT white-collar workers in a first-tier city is 30 thousand RMB per year."/"is invalid.


If the filtering method is not found in Apache Common FilenameUtils, you can write a simple filtering method and replace "/" and other characters with "".
Java Regular Expression replacement: filteredName = name. replaceAll ("[/<> | \"? :] "," "). ReplaceAll ("\\\\","");


3. Incomplete log4j output information.
<Param name = "ConversionPattern"
Value = "[% d {yyyy-MM-dd HH: mm: ss \} %-5 p] [% t] % l-% X {loginUser} % X {userip} % m % n "/>

% C indicates the full name of the output class, which can be changed to the dimension output by % d {Num} And Num Class Name (for example, "org. apache. elattings. className ", % C {2} Will output elattings. className)
% L location of log event output, including category name, thread, number of lines in the code
 
% L is more useful than % c, that is, the information is a little longer.
If you do not know the row number, it is slower to locate the log.


4. Check the paging parameter, but it is still not comprehensive enough. The pageSize is null.
It seems that the consideration is still not comprehensive.
Previously, we checked whether pageSize and pageNo are positive numbers and the range.

5. The search parameter is null.
The backend performs a Null check, but the front end does not enter a "search term". It also performs backend queries, which is a waste.
Add JS checks on the front end to reduce unnecessary request processing on the server side.

6. Code conflicts often occur during website deployment.
For the first deployment, there are several directories, such as article and article. service.
However, during the second deployment, the code was restructured and only article had a directory. At this time, copy-paste was replaced for deployment,
The article. service Directory still exists, which may lead to a class file, such as SearchService, which has two.
Cause Spring @ Autowired to report an error.


This problem reminds us that the previous code needs to be cleared during deployment. Of course, for the sake of security, it is best to perform a full backup first.


7. When the Maven project is packaged, the xml file is not packaged, so it is ignored directly.
Until January 8, 2015, maven has never been manually configured to package xml. This time, something went wrong and I had to add some configuration in pom. xml.
<Build>
<Plugins>
</Plugins>
<Resources>
<Resource>
<Directory> src/main/java </directory>
<Shortdes>
<Include> **/*. xml </include>
</Shortdes>
</Resource>
</Resources>
</Build>


8. p2p trial operation.
Many platforms have a "Trial Operation" phase, before the "official launch. This is a transitional phase. If any problem occurs, fix it in time.
In the trial operation phase, there are usually not too many users, and the loss will not be too great.


"Trial Operation" is similar to "Public Beta" for online games.


9. When using a file, it is necessary to check whether the file exists.
File file = new File (log4jXmlPath );
Boolean exist = file. exists ();
Using the exists method is much more friendly than capturing java. io. FileNotFoundException.

10. In the java web project, the location of log4j. xml and the log output directory of log4j can be configured.
<Servlet-name> Log4jInit </servlet-name>
<Servlet-class> cn. fansunion. common. web. Log4jInit </servlet-class>
<Init-param>
<Param-name> log4jOutputPath </param-name>
<Param-value> C:/log4j/xiaolei </param-value>
</Init-param>
<Init-param>
<Param-name> log4jXmlPath </param-name>
<Param-value> C:/log4j. xml </param-value>
</Init-param>
</Servlet>
Configure the variables in web. xml, write the initialization servlet of log4j, parse the variables in the servlet, and then manually initialize log4j.

System. setProperty ("log4jOutputPath", log4jOutputPath );
DOMConfigurator. configure (log4jXmlPath );

It took more than an hour to write and test the servlet.
The detailed custom configuration will not be shared in this article.


I have been operating on my official website for a while. I have found many problems by checking the logs of the last two months.
At present, some of them have been fixed.
Other problems are solved one by one, with too many technical details.

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.