2020-07-29 16:24

@JFinal 就是在controller里面,注入一下NoticeService就可以了是吧

2020-06-15 21:22

@JFinal 好的,谢谢了。我试试。还有我项目里面很多地方用到redirect(),这个方法,都要把redirect()改成render(new MyRedirectRender(...))吗,

2020-06-15 18:50

@谢 需要在JFinalConfig里面添加什么吗?

2020-06-15 18:42

@谢 我按照你的文档,做了。还是不行啊 nginx修改:
location / {
proxy_pass http://127.0.0.1:8081;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-Port $server_port;
}

Java 后台:因为我的是3.4版本,继承RedirectRender之后,这三个参数url,withQueryString,contextPath我有定义了一下,private String url;
private boolean withQueryString;

private static final String contextPath = getContxtPath();
package com.jfinalshop.render;

import com.jfinal.core.JFinal;
import com.jfinal.kit.StrKit;
import com.jfinal.render.RedirectRender;

/**
* RedirectRender with status: 302 Found.
*
*
* 注意:使用 nginx 代理实现 https 的场景,解决 https 被重定向到了 http 的问题,需要在 nginx 中添加如下配置:
* proxy_set_header X-Forwarded-Proto $scheme;
* proxy_set_header X-Forwarded-Port $server_port;
*
*
* PS:nginx 将 http 重定向到 https 的配置为:
* proxy_redirect http:// https://;
* 注意: 需要同时支持 http 与 https 的场景不能使用该配置
*
*/
public class MyRedirectRender extends RedirectRender {

private String url;
private boolean withQueryString;

private static final String contextPath = getContxtPath();

static String getContxtPath() {
String cp = JFinal.me().getContextPath();
return !"".equals(cp) && !"/".equals(cp) ? cp : null;
}

public MyRedirectRender(String url) {
super(url);
}

public MyRedirectRender(String url, boolean withQueryString) {
super(url, withQueryString);
}

@Override
public String buildFinalUrl() {
String ret;
// 如果一个url为/login/connect?goto=http://www.jfinal.com,则有错误
// ^((https|http|ftp|rtsp|mms)?://)$ ==> indexOf 取值为 (3, 5)
if (contextPath != null && (url.indexOf("://") == -1 || url.indexOf("://") > 5)) {
ret = contextPath + url;
} else {
ret = url;
}

if (withQueryString) {
String queryString = request.getQueryString();
if (queryString != null) {
if (ret.indexOf('?') == -1) {
ret = ret + "?" + queryString;
} else {
ret = ret + "&" + queryString;
}
}
}

// 跳过 http/https 已指定过协议类型的 url,用于支持跨域名重定向
if (ret.toLowerCase().startsWith("http")) {
return ret;
}

/**
* 注意:nginx 代理 https 的场景,需要使用如下配置:
* proxy_set_header X-Forwarded-Proto $scheme;
* proxy_set_header X-Forwarded-Port $server_port;
*/
if ("https".equalsIgnoreCase(request.getHeader("X-Forwarded-Proto"))) {
String serverName = request.getServerName();

/**
* 获取 nginx 端通过配置 proxy_set_header X-Forwarded-Port $server_port;
* 传递过来的端口号,保障重定向时端口号是正确的
*/
String port = request.getHeader("X-Forwarded-Port");
if (StrKit.notBlank(port)) {
serverName = serverName + ":" + port;
}

if (ret.charAt(0) != '/') {
return "https://" + serverName + "/" + ret;
} else {
return "https://" + serverName + ret;
}

} else {
return ret;
}
}
}

2020-06-15 17:37

@谢 好的,谢谢了

2020-06-15 17:21

@谢 之前是http的,然后网站换成https的了,然后redirect重定向就跳转不了了,这个改怎么解决啊