部署web项目在linux服务器需要注意的一些问题

- 1 数据库乱码问题

我用的是mysql数据库,通过阿里的jedis连接池获取配置文件进行动态加载

	driverClassName=com.mysql.jdbc.Driver
	url=jdbc:mysql:///数据库名?characterEncoding=utf-8
	username=用户名
	password==密码
	# 初始化连接数量
	initialSize=5
	# 最大连接数
	maxActive=10
	# 最大等待时间
	maxWait=3000

在数据库名后面记得加characterEncoding=utf-8

- 2 tomcat get请求乱码问题

  • Tomcat配置:
    更改两个位置的配置文件
    1.server.xml

在这里插入图片描述

<Connector port='8080' protocol="HTTP/1.1" connectionTimeout="20000" redirectProt="8443" URIEncoding="utf-8"/>

是为了解决get请求处理中文数据乱码问题!

  • post请求乱码可以自定义一个过滤器
 public void doFilter(ServletRequest req, ServletResponse rep, FilterChain filterChain) throws IOException, ServletException {
        //将父接口转为子接口
        HttpServletRequest request = (HttpServletRequest) req;
        HttpServletResponse response = (HttpServletResponse) rep;
        //获取请求方法
        String method = request.getMethod();
        //解决post请求中文数据乱码问题
        if(method.equalsIgnoreCase("post")){
            request.setCharacterEncoding("utf-8");
        }
        //处理响应乱码
        response.setContentType("text/html;charset=utf-8");
        filterChain.doFilter(request,response);
    }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值