Springside's default database is hsql, but most developers are familiar with MySQL. Therefore, in actual development, the first thing they encounter is to modify the database. It is very easy to modify the database in springside, or the xkland project created in the previous article. First, modify the JDBC in the src/main/resources/config folder. in the properties file, comment out lines 1 and 2, uncomment lines 7 and 8, and modify the username and password of lines 10 and 11, as shown below:
1 # JDBC. driverclassname = org. HSQLDB. jdbcdriver
2 # JDBC. url = JDBC: HSQLDB: Res:/HSQLDB/helloworld
3
4 # JDBC. driverclassname = oracle. JDBC. Driver. oracledriver
5 # JDBC. url = JDBC: oracle: thin: @ localhost: helloworld
6
7jdbc. driverclassname = com. MySQL. JDBC. Driver
8jdbc. url = JDBC: mysql: // localhost: 3306/xkland? Useunicode = true & characterencoding = utf8
9
10jdbc. Username = xkland
11jdbc. Password = xkland
Next, modify the hibernate. properties file in the src/main/resources/config folder, comment out the first line, and comment out the second line, as shown below:
1 # hibernate. dialect = org. hibernate. dialect. hsqldialect
2hibernate. dialect = org. hibernate. dialect. mysql5dialect
3 # hibernate. dialect = org. hibernate. dialect. oracle9dialect
4hibernate. show_ SQL = false
5hibernate. cache. use_query_cache = true
6hibernate. cache. provider_class = org. hibernate. cache. ehcacheprovider
This process is simple, but there is another important thing to note: Remember to drive MySQL with JDBC provided by MySQL. jar copy to src/main/webapp/WEB-INF/lib folder, otherwise, the following error occurs:
Springside attaches great importance to i18n support. Therefore, it is very convenient to create an international application. You only need to add the corresponding resource file under the src/Mian/resources/i18n folder. Springside uses UTF-8 encoding by default, which can be seen from the encodingfilter registered in Web. XML, of course, you can also choose your favorite character encoding, such as gb2312. If you want to modify the character encoding, remember that there are four parts to be consistent:
1. encodingfilter configuration in Web. XML is as follows:
<Filter>
<Filter-Name> encodingfilter </filter-Name>
<Filter-class> org. springframework. Web. Filter. characterencodingfilter </filter-class>
<Init-param>
<Param-Name> encoding </param-Name>
<Param-value> UTF-8 </param-value>
</Init-param>
</Filter>
2. The default character set in the database must be specified when the data table is created, as shown below:
Create Table 'user '(
'Id' int (11) not null auto_increment,
'Username' varchar (20 ),
'Password' char (32 ),
Primary Key ('id ')
) Engine = InnoDB default charset = utf8
3. Set the JDBC connection in src/main/resources/config/jdbc. properties, as shown below:
JDBC. url = JDBC: mysql: // localhost: 3306/xkland? Useunicode = true & characterencoding = utf8
4. The page code in the JSP page is as follows:
<% @ Page contenttype = "text/html; charset = UTF-8" %>
<Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8"/>
As long as the four parts are set to the same, the JSP page should not be garbled. In the final analysis, the encodingfilter registered by springside in Web. XML is very helpful. However, it is not that convenient to read the message from the struts resource bundle, because you need to create the following messages_zh_cn.properties file:
# -- Direct output message --
Message = {0}
# -- Crud message
Entity. Saved =/u6210/u529f/u4fdd/u5b58/u3002
Entity. Missing =/u627e/u4e0d/u5230/u6b64id/u7684/u5bf9/u8c61/u3002
Entity. Deleted =/u6210/u529f/u5220/u9664/u3002
# -- Validator errors --
Errors. Required = {0}/u4e3a/u5fc5/u586b/u9879/u3002
Errors. maxlength = {0}/u4e0d/u80fd/u5927/u4e8e {1}/u4e2a/u5b57/u7b26/u3002
Errors. minlength = {0}/u4e0d/u80fd/u5c11/u4e8e {1}/u4e2a/u5b57/u7b26/u3002
Errors. Invalid = {0}/u65e0/u6548/u3002
Errors. byte = {0}/u5fc5/u987b/u4e3abyte/u7c7b/u578b/u3002
Errors. Double = {0}/u5fc5/u987b/u4e3adouble/u7c7b/u578b/u3002
Errors. Float = {0}/u5fc5/u987b/u4e3afloat/u7c7b/u578b/u3002
Errors. Integer = {0}/u5fc5/u987b/u4e3a/u4e00/u6570/u503c/u3002
Errors. Long = {0}/u5fc5/u987b/u4e3along/u7c7b/u578b/u3002
Errors. Short = {0}/u5fc5/u987b/u4e3ashort/u7c7b/u578b/u3002
Errors. Date = {0}/u4e0d/u662f/u6709/u6548/u65e5/u671f/u683c/u5f0f/u3002
Errors. range = {0}/u672a/u5728 {1}/u4e0e {2}/u8303/u56f4/u5185/u3002
Errors. creditcard = {0}/u4e3a/u65e0/u6548/u4fe1/u7528/u5361/u53f7/u3002
Errors. Email = {0}/u4e3a/u65e0/u6548/u90ae/u4ef6/u5730/u5740/u3002
Errors. Phone = {0}/u4e3a/u65e0/u6548/u7535/u8bdd/u53f7/u7801/u3002
Errors.zip = {0}/u4e3a/u65e0/u6548/u90ae/u653f/u7f16/u7801/u3002
Hello =/u4f60/u597d/uff0cspringside!
To accelerate development and debugging, You can compile a batch processing file make_resource.bat, as shown below: native2ascii-encoding UTF-8 src/main/resources/i18n/temp.txt src/main/resources/i18n/messages_zh_cn.properties
Then, register the batch processing file as an external tool of Eclipse, such:
Later, modify messagesin temp.txt, and then run the external tool. Quick and convenient.
No one can write a project in one breath and then run it again. All programmers need to modify the code while running the program to observe the modification effect. However, springside provides Quickstart. bat has many problems, causing programmers to be unable to quickly deploy the program. There are two reasons: Quick Start. every time bat runs, it is too slow to re-build the project, update the component library, and start the Tomcat server. The second is to run Quickstart. after bat, even if the console window is closed, the Tomcat server will still run in the background, so that the next time you run Quickstart. bat will encounter an error and prompt that the file cannot be cleaned up.
It is not difficult to solve these two problems. You can set the startup in the MISC/servers/tomcat-5.5.17/bin directory under the springside root directory. BAT and shutdown. bat registers as an external tool for eclispe to quickly start and close the Tomcat server, for example:
In addition, you do not need to restart the server. You only need to redeploy the changed files to the server. In the springside root directory, the MISC/servers/tomcat-5.5.17/webapps folder contains all springside projects. You can deploy the modified. Class file, configuration file, resource file, and. jsp file on the server using the command line tool xcopy provided by windows. Create a batch file deploy. BAT as follows:
Xcopy src/main/webapp/*. jsp E:/springside-2.0/MISC/servers/tomcat-5.5.17/webapps/xkland/D/y
Xcopy bin/*. * E:/springside-2.0/MISC/servers/tomcat-5.5.17/webapps/xkland/WEB-INF/classes/S/D/y
Xcopy src/main/resources/*. * E:/springside-2.0/MISC/servers/tomcat-5.5.17/webapps/xkland/WEB-INF/classes/S/D/y
Xcopy src/main/webapp/WEB-INF/*. xml E:/springside-2.0/MISC/servers/tomcat-5.5.17/webapps/xkland/WEB-INF/D/y
The/s option is the copy sub-directory, the/D option is to copy only the updated files, and the/Y option is not to ask whether to overwrite.
Then register the deploy. BAT as an external tool of Eclipse. No, it's cumbersome.
After modifying the struts configuration file and action class, Struts reads the configuration file and caches it only once at Tomcat startup, the action object only creates an instance when it is used for the first time. Therefore, you must restart the server to see the effect. It can be used with the preceding deploy, stop_tomcat, and start_tomcat external tools, this makes it easier to deploy and debug springside applications.