解决展示看板页面上的网页资源链接点击后显示的是目标源码的BUG

This commit is contained in:
datagear 2020-02-29 13:36:23 +08:00
parent a9dea6e066
commit b14495cbcf
2 changed files with 66 additions and 2 deletions

View File

@ -15,6 +15,7 @@ import java.util.Locale;
import java.util.Map;
import java.util.Set;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@ -49,6 +50,7 @@ import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.context.ServletContextAware;
import org.springframework.web.context.request.WebRequest;
/**
@ -59,7 +61,7 @@ import org.springframework.web.context.request.WebRequest;
*/
@Controller
@RequestMapping("/analysis/chart")
public class ChartController extends AbstractChartPluginAwareController
public class ChartController extends AbstractChartPluginAwareController implements ServletContextAware
{
static
{
@ -76,6 +78,8 @@ public class ChartController extends AbstractChartPluginAwareController
@Qualifier("chartShowHtmlTplDashboardWidgetHtmlRenderer")
private HtmlTplDashboardWidgetHtmlRenderer<HtmlRenderContext> chartShowHtmlTplDashboardWidgetHtmlRenderer;
private ServletContext servletContext;
public ChartController()
{
super();
@ -122,6 +126,17 @@ public class ChartController extends AbstractChartPluginAwareController
this.chartShowHtmlTplDashboardWidgetHtmlRenderer = chartShowHtmlTplDashboardWidgetHtmlRenderer;
}
public ServletContext getServletContext()
{
return servletContext;
}
@Override
public void setServletContext(ServletContext servletContext)
{
this.servletContext = servletContext;
}
@RequestMapping("/add")
public String add(HttpServletRequest request, org.springframework.ui.Model model)
{
@ -323,6 +338,8 @@ public class ChartController extends AbstractChartPluginAwareController
TemplateDashboardWidgetResManager resManager = this.chartShowHtmlTplDashboardWidgetHtmlRenderer
.getTemplateDashboardWidgetResManager();
setChartResResponseContentType(request, response, resName);
long lastModified = resManager.lastModifiedResource(id, resName);
if (webRequest.checkNotModified(lastModified))
return;
@ -393,6 +410,21 @@ public class ChartController extends AbstractChartPluginAwareController
dashboardManager.put(dashboard);
}
/**
* 设置图表资源响应内容类型
*
* @param request
* @param response
* @param resName
*/
protected void setChartResResponseContentType(HttpServletRequest request, HttpServletResponse response,
String resName)
{
String mimeType = getServletContext().getMimeType(resName);
if (!isEmpty(mimeType))
response.setContentType(mimeType);
}
/**
* 解析展示图表请求路径的看板资源名
* <p>

View File

@ -16,6 +16,7 @@ import java.util.List;
import java.util.Map;
import java.util.zip.ZipInputStream;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@ -48,6 +49,7 @@ import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.context.ServletContextAware;
import org.springframework.web.context.request.WebRequest;
import org.springframework.web.multipart.MultipartFile;
@ -59,7 +61,7 @@ import org.springframework.web.multipart.MultipartFile;
*/
@Controller
@RequestMapping("/analysis/dashboard")
public class DashboardController extends AbstractDataAnalysisController
public class DashboardController extends AbstractDataAnalysisController implements ServletContextAware
{
static
{
@ -73,6 +75,8 @@ public class DashboardController extends AbstractDataAnalysisController
@Autowired
private File tempDirectory;
private ServletContext servletContext;
public DashboardController()
{
super();
@ -107,6 +111,17 @@ public class DashboardController extends AbstractDataAnalysisController
this.tempDirectory = tempDirectory;
}
public ServletContext getServletContext()
{
return servletContext;
}
@Override
public void setServletContext(ServletContext servletContext)
{
this.servletContext = servletContext;
}
@RequestMapping("/add")
public String add(HttpServletRequest request, org.springframework.ui.Model model)
{
@ -546,6 +561,8 @@ public class DashboardController extends AbstractDataAnalysisController
if (!resManager.containsResource(id, resName))
throw new FileNotFoundException(resName);
setDashboardResResponseContentType(request, response, resName);
long lastModified = resManager.lastModifiedResource(id, resName);
if (webRequest.checkNotModified(lastModified))
return;
@ -625,6 +642,21 @@ public class DashboardController extends AbstractDataAnalysisController
return getDashboardData(request, response, model, webContext);
}
/**
* 设置看板资源响应内容类型
*
* @param request
* @param response
* @param resName
*/
protected void setDashboardResResponseContentType(HttpServletRequest request, HttpServletResponse response,
String resName)
{
String mimeType = getServletContext().getMimeType(resName);
if (!isEmpty(mimeType))
response.setContentType(mimeType);
}
/**
* 解析展示看板请求路径的看板资源名
* <p>