Summary of myeclipse + freemarker framework development

Source: Internet
Author: User

Summary of myeclipse + freemarker framework development

2009-03-03
10: 33

Garbled characters are always encountered during development. Therefore, you can collect and extract the information on the Internet for future query.

1. Text garbled by JS comments in myeclipse

For garbled characters, there are mainly settings related to myeclipse. You can find the JSP tab window under the editors tab in the myeclipse tab, which has an encoding attribute value, you can select Chinese to solve the problem of Garbled text display! The myeclipse syntax error prompt will not be caused by garbled characters!

Now I will focus on the solutions to the problems that cause syntax errors. For general web application development, I personally do not recommend using the myeclipse plug-in. I personally recommend using the WTP plug-in, at present, the official website also integrates this plug-in into eclipse, which shows the ease-of-use and availability of this plug-in. Download Java EE from the eclipse website
Developers version! This version is very suitable for web project development. This plug-in can solve all the above problems. However, it is not recommended to use myeclipse.

2. When you use the Tomcat server, garbled characters will appear when you pass Chinese parameters in the jump path!

For example
Href = "Servlet/loginservlet? Flag = test ">
And <form name = "form1" action
= "Servlet/loginservlet? Flag = "test" method = "Post"> the request. getparameter ("flag") is used in loginservlet in the two methods.

Solution: Add a piece of code to Tomcat/CONF/servlet. xml:

<Connector Port = "8090" maxthreads = "150"
Minsparethreads = "25" maxsparethreads = "75"

Enablelookups = "false" redirectport = "8443"
Acceptcount = "100"

DEBUG = "0" connectiontimeout = "20000"

Disableuploadtimeout = "true" uriencoding = "true"/>

3. If the parameter transmitted in the URI is to be sent to the JSP page, the Code must be added to the JSP page where the code is accepted:
<% Request. setcharacterencoding ("gb2312"); %>

4. After adding Chinese characters to the. js file and adding them to my‑e, the Code becomes garbled, but the webpage can correctly display Chinese characters. How can this problem be solved?

In myeclipse
Search for Javascript in the preferences-attribute and search for its editing
Change Encoding under files
Chinese, the national standard is good, that is, gb18030.
.

5. Garbled text output by JS in the browser

If the encoding rules of the Web application are UTF-8, such:
<Meta http-equiv = "Content-Type" content = "text/html;
Charset = UTF-8 "/>
If the JS file contains Chinese output, garbled characters will occur. To solve this problem, add charset = "gb2312" to the place where the Javascript output is referenced"
Or charset = "big5" (assuming big5 traditional Chinese characters are output ).

Example:
<SCRIPT type = "text/JavaScript" Language = "JavaScript"
Src = "scripts/output. js"
Charset = "gb2312"> </SCRIPT>

6. Reference multiple JS files. The inntext output contains Chinese garbled characters.

The original JS files have never been concerned about their encoding. However, later I did not know how to find that some files are good for being referenced to a page at the same time, especially when JavaScript contains Chinese characters. Sometimes Chinese characters are garbled in the browser. One by one. Finally, the cause is found.

Generally, we save text files in Chinese OS. By default, they are all encoded in gb2312 format. However, when we write "? "After saving these symbols, you will be prompted to save them in unicode format. If you ignore it and save it as gb2312, you will find "? ""? "@_@. There are also some such characters, such as high ASCII characters in windows, whose Unicode definition is some strange characters. If these characters are forcibly saved using gb2312, after it is opened, it is merged into Chinese characters or garbled characters.

Back to the encoding of our script files, if we reference multiple JavaScript files on the same page, and the storage encoding of these files is different (with gb2312 and Unicode ), an error may occur. Of course, this is not always the most terrible thing. Because 7bit
ASCII code, no matter what encoding is generic, there will be no decoding problem, but if the file contains Chinese characters, there may be errors.

For example, the JS file stored in gb2312 is Var Str.
= 'This is a gb2312 encoded file. ';
VaR description = 'this file saved as gb2312 encoding. '; can be correctly referenced in IE encoded as gb2312.

Javascript file saved by Unicode encoding: VaR
Strw = 'This is a unicode encoded file. ';
VaR descriptionw = 'this file saved as Unicode encoding. '; can be correctly referenced in IE that is encoded as Unicode.


The two files cannot be correctly executed no matter how IE encoding is selected in the following references.
<HTML>
<Head>
<Title> test encode </title>
<SCRIPT src = "Unicode. js"
Language = "JavaScript"> </SCRIPT>
<SCRIPT src = "gb2312.js"
Language = "JavaScript"> </SCRIPT>
</Head>
<Body>
<Script language = "JavaScript">
Alert (strw + '/R/N' + descriptionw );
Alert (STR + '/R/N' + description );
</SCRIPT>
</Body>
</Html>


My solution is: the code of the page must be consistent with that of the page. For example, my FTL file is UTF-8 encoded. I usually open the JS file in notepad. And save it as another one. The name is not changed. Only change the following encoding to UTF-8 format.

Then reference JS <script
Src = "Public/script/toadduser. js" Language = "javascript1.2"
Charset = "gb2312"> </SCRIPT>
Start the service again. The problem is solved!

7. The freemarker + springmvc framework does not know how to intercept Chinese strings of the specified length in the. FTL file. freemakert has its own function.

You can also use CSS to control the duration. But there is a drawback. Only one row of data can be displayed. It won't work if there are multiple rows. I used the freemarker framework. Have your own functions. Otherwise, JavaScript or server-side control is required.

<# If
News. Title? Length Lt 13>
$ {NEWS. Title}
<# Else>
$ {NEWS. Title [0... 12]}...
</# If>

By the way: the meaning of ISO8859-1, UTF-8, and gb2312

ISO8859-1, usually called Latin-1. Latin-1 includes additional characters that are indispensable for writing all Western European languages.
Gb2312 is a standard Chinese character set.
UTF-8 is a variable-length character encoding of Unicode, that is, RFC
3629. To put it simply, it is a big character set. It can solve the problem of text display in multiple languages, so as to realize the internationalization and localization of applications.

For the system, UTF-8 encoding can be quickly read and written by shielding bit and shift operations, sorting is easier. The UTF-8 is unrelated to the byte order, and its byte order is the same in all systems. So UTF-8 has higher performance.

However, if it is only in English, you can use anything. It is no problem to use gb2312.

8. After I restart my machine on the ghost, start myuld s and the "cocould
Not create the Java Virtual Machine "error Solution

1. In D:/Program
Files/myeclipse 6.1 blue/eclipse has an eclipse. ini file. The original configuration is as follows:

-Showsplash

Com. genuitec. myeclipse. Blue. Product. ide

-- Launcher. xxmaxpermsize

256 m

-Vmargs

-Xms128m

-Xmx512m

-Duser. language = EN

XX: permsize = 128 m

-XX: maxpermsize = 256 m


2. Change the original configuration to the following:

-Showsplash

Com. genuitec. myeclipse. Blue. Product. ide

-- Launcher. xxmaxpermsize

256 m

-Vmargs

-Xms128m

-Xmx512m

-Duser. language = EN

-XX: permsize = 64 m
// Modify it here

-XX: maxpermsize = 128 m


After modifying the above Code, myeclipse can start

In addition, this configuration also exists in eclipse, and the maximum memory cannot be greater than its own memory.

 

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.