[英]How to open a popup window with custome length and width size in Spring MVC Projects using Javascript, Ajax, and Java with JSP file?
I want to open a pop-up window with custome length and width of the window by using Javascript, Ajax on JSP. I want to open a pop-up window with custome length and width of the window by using Javascript, Ajax on JSP. How do I do this?
我该怎么做呢?
I have solved it in my Spring MVC Project by the following way:我已经通过以下方式在我的 Spring MVC 项目中解决了它:
The Controller class is like this: Controller class是这样的:
@RequestMapping(value = "viewPicture.dispatch", method = RequestMethod.GET)
public String viewPicture(HttpServletRequest request, RequestParam(value="fileName")String fileName, @RequestParam(value="filePath")String filePath) {
//some code..
return "viewDCPicture"; //the View where it will go.
}
The JSP page on which I have written JS and Html code also, is like this:我写过JS和Html代码的JSP页面也是这样的:
<script>
function viewDCPicture(fileName){
var filePath = $("#filePath").val();
//Setting the left and right size of the pop-up window
var left = (screen.width/2)-(1100/2);
var top = (screen.height/2)-(170/2);
$.ajax({
method: "GET",
url : "viewPicture.dispatch?fileName=" + fileName + "&filePath=" + filePath,
success : function(response) {
var strURL = "viewPicture.dispatch?fileName=" + fileName + "&filePath=" + filePath + "";
window.open(strURL, 'viewDCPicture', 'width=1100, height=600, resizable=1, scrollbars=yes, location=0, status=0, titlebar=no, toolbar=0, addressbar=0, top='+top+', left='+left+'');
},
error : function(e) {
}
});
}
</script>
<table>
<tr>
<td align="right"><label>SUPPORTING DOCS.</label></td>
<c:forEach items="${attachmentDtlList}" var="data">
<td>
<a href="javascript:void(0)" title="Picture" onclick = "viewDCPicture('${data.key}');">${data.key}</a>
<input type="hidden" id="filePath" value="${data.value}">
</td>
</c:forEach>
</tr>
</table>
In my template.xml where the JSP files are mapped with the perticular name = "viewDCPicture"
, I have made changes like this:在我的template.xml中,JSP 文件映射为特定
name = "viewDCPicture"
,我进行了如下更改:
I have created a template inside the template.xml file as:我在 template.xml 文件中创建了一个模板,如下所示:
<definition name = "viewDocTemplate" template = "/viewDoc.jsp">
<put-attribute name = "body" value = "" />
</definition>
And used it inside the temlate.xml file as:并在 temlate.xml 文件中使用它:
<definition extends = "viewDocTemplate" name = "viewDCPicture">
<put-attribute name = "body" value = "/enquiry_management/viewDCPicture.jsp" />
</definition>
The viewDoc.jsp file which will help the Pop-up window file viewDCPicture.jsp to bind it inside body of viewDoc.jsp is as follows: The viewDoc.jsp file which will help the Pop-up window file viewDCPicture.jsp to bind it inside body of viewDoc.jsp is as follows:
<%@ page language = "java" contentType = "text/html; charset = UTF-8"
pageEncoding = "UTF-8"%>
<%@ taglib prefix = "c" uri = "http://java.sun.com/jsp/jstl/core"%>
<%@ taglib uri = "http://tiles.apache.org/tags-tiles" prefix = "tiles"%>
<%@ taglib uri = "http://www.springframework.org/tags" prefix = "spring"%>
<!DOCTYPE html>
<html>
<head>
<meta charset = "UTF-8">
<title>Insert title here</title>
</head>
<body>
<%-- Adding spring attribute for adding body, header, footer etc tag. --%>
<spring:htmlEscape defaultHtmlEscape = "true" />
<tiles:insertAttribute name = "body" />
</body>
</html>
The viewDCPicture.jsp file is like this: viewDCPicture.jsp文件是这样的:
<html>
<head>
</head>
<table align="center" class="headingSpas">
<tr>
<td class="headingSpas">
<table width="100%" align="center" bgcolor="#CCCCCC">
<tr>
<td colspan="2" align="center" class="headingSpas" >
<img alt="" src="<%=path%>" border="0" align="top" />
</td>
</tr>
</table>
</td>
</tr>
</table>
</html>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.