Experience the real struts development 3 (2)

zhaozj2021-02-17  71

We write resource files

Password = Password format error

UserName = account format error

HBM.Session.Error = Establish an Hibernate Session error.

No.user = This is not found to have users.

HBM.Session.Query = Hibernate HQL query error.

Errors.Header =

    Errors.footer =

    Logon = landing

    Logon.username = account number

    Logon.password = password

    Save to C: /1.txt

    Then run

    Native2ascii -Encoding GBK C: /1.TXT C: /ApplicationResources_zh_cn.properties

    Will be generated C: /ApplicationResources_zh_cn.properties to copy to the src directory, we re-run this login program.

    There is garbled, we forgot to set the JSP page encoding into UTF-8, add

    ContentType = "text / html; charSet = UTF-8", refresh again

    OK success

    When you enter Chinese in the account box, it will appear in the picture.

    There is a garbled, so that there is 3 cases:

    1. Set Response to coding in each action, this method is more cumbersome, and each Action must be set once.

    2. Use the filter in servlet2.3, unified settings

    3. Overload the Process function in the ActionServlet.

    The first method is difficult to obtain an encoding method through an XML configuration.

    2, 3 can be solved by configuring parameters in Web.xml

    This article describes how to use it, filter Filter

    There is a ready-made coded filter under the Filter folder inside the Samples in Tomcat.

    Copying, in Eclipse uses reconstruction, solve the Package mismatch problem.

    The following is a web.xml for this filter.

    Filter

    ->

    Set Character Encoding

    com.yjsoft.filter.setcharacterencodingfilter

    Encoding

    UTF-8

    Set Character Encoding

    / *

    end

    ->

    Start Tomcat test again, OK.

转载请注明原文地址:https://www.9cbs.com/read-30017.html

New Post(0)