JavaWeb_(Struts2框架)Log4j的配置以及解决中文乱码

 

 

 

解决web项目中文乱码问题

  在项目目录WebContent->WEB-INF->web.xml下中再配置两个节点

      <init-param>
          <param-name>encodingparam-name>
          <param-value>UTF-8param-value>
      init-param>

 

xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1">
  <display-name>StrutsForum_Logindisplay-name>
  <welcome-file-list>
    <welcome-file>index.htmlwelcome-file>
    <welcome-file>index.htmwelcome-file>
    <welcome-file>index.jspwelcome-file>
    <welcome-file>default.htmlwelcome-file>
    <welcome-file>default.htmwelcome-file>
    <welcome-file>default.jspwelcome-file>
  welcome-file-list>
  
  <filter>
      <filter-name>strutsfilter-name>
      <filter-class>org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilterfilter-class>
        
      <init-param>
          <param-name>encodingparam-name>
          <param-value>UTF-8param-value>
      init-param>
      
  
  filter>
  <filter-mapping>
      <filter-name>strutsfilter-name>

      <url-pattern>/*url-pattern>
  filter-mapping>
  
web-app>
web.xml

 

 

Log4j的配置

  项目可以添加log4j-api-2.11.0和log4j-core-2.11.0的jar包

  配置log4j2.xml

xml version="1.0" encoding="UTF-8"?>
    <Configuration>
        <Appenders>
            <Console name="STDOUT" target="SYSTEM_OUT">
                <PatternLayout pattern="%d %-5p [%t] %C{2} (%F:%L) - %m%n"/>
            Console>
            <RollingFile name="RollingFile" fileName="logs/strutslog1.log"
                         filePattern="logs/$${date:yyyy-MM}/app-%d{MM-dd-yyyy}-%i.log.gz">
                <PatternLayout>
                    <Pattern>%d{MM-dd-yyyy} %p %c{1.} [%t] -%M-%L- %m%nPattern>
                PatternLayout>
                <Policies>
                    <TimeBasedTriggeringPolicy />
                    <SizeBasedTriggeringPolicy size="1 KB"/>
                Policies>
                <DefaultRolloverStrategy fileIndex="max" max="2"/>
            RollingFile>
        Appenders>
        <Loggers>
            <Logger name="com.opensymphony.xwork2" level="WAN"/>
            <Logger name="org.apache.struts2" level="WAN"/>
            <Root level="warn">
                <AppenderRef ref="STDOUT"/>
            Root>
        Loggers>
     
     
    Configuration>
log4j2.xml

 

转载于:https://www.cnblogs.com/1138720556Gary/p/11572985.html

你可能感兴趣的:(JavaWeb_(Struts2框架)Log4j的配置以及解决中文乱码)