admin管理员组文章数量:1399997
I need to open a new window from a jsp file. In a JSP file, I take in an input from the user and then send it as an argument to a java method which returns me back the url as a string. I then need to open this in a new window. How do I do that? Below is the jsp file(send_product.jsp) for your reference.
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ page import="products.*" %>
<!DOCTYPE html>
<%
productManager pm= new productManagerImpl();
String myUrl= null;
if (request.getParameter("product_id") != null) {
// get the paramter
String product_id = request.getParameter("product_id");
try {
//myUrl has the url. Have to open this in a new window
myUrl = pm.getUrl(product_id);
} catch (Exception ex) {
ex.printStackTrace();
}
}
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert</title>
</head>
<body bgcolor="wheat">
<h4 align="right">Send Product</h4>
<hr color="red"/>
<br/><br/>
<a href="index.jsp">Index</a>
<form action="send_product.jsp" method="post">
<% if (myUrl != null && !myUrl.equals("")) {%>
<%= myUrl%>
<p> </p>
<%
}
%>
<table width="75%" align="center" >
<tr>
<td>
Please enter the information below and click "<b>Submit</b>"
</td>
</tr>
<tr>
<td>
<fieldset title="info">
<table border="0" cellspacing="3" cellpadding="0" align="center">
<tr>
<td align="right">
* Product ID:
</td>
<td align="left">
<input type="text" size="20" maxlength="70" name="product_id">
</td>
</tr>
</table>
<hr />
<div align="center">
<input type="submit" name="saveInfo" value="Submit">
</div>
</fieldset>
</td>
</tr>
</table>
</form>
</body>
</html>
I need to open a new window from a jsp file. In a JSP file, I take in an input from the user and then send it as an argument to a java method which returns me back the url as a string. I then need to open this in a new window. How do I do that? Below is the jsp file(send_product.jsp) for your reference.
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ page import="products.*" %>
<!DOCTYPE html>
<%
productManager pm= new productManagerImpl();
String myUrl= null;
if (request.getParameter("product_id") != null) {
// get the paramter
String product_id = request.getParameter("product_id");
try {
//myUrl has the url. Have to open this in a new window
myUrl = pm.getUrl(product_id);
} catch (Exception ex) {
ex.printStackTrace();
}
}
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert</title>
</head>
<body bgcolor="wheat">
<h4 align="right">Send Product</h4>
<hr color="red"/>
<br/><br/>
<a href="index.jsp">Index</a>
<form action="send_product.jsp" method="post">
<% if (myUrl != null && !myUrl.equals("")) {%>
<%= myUrl%>
<p> </p>
<%
}
%>
<table width="75%" align="center" >
<tr>
<td>
Please enter the information below and click "<b>Submit</b>"
</td>
</tr>
<tr>
<td>
<fieldset title="info">
<table border="0" cellspacing="3" cellpadding="0" align="center">
<tr>
<td align="right">
* Product ID:
</td>
<td align="left">
<input type="text" size="20" maxlength="70" name="product_id">
</td>
</tr>
</table>
<hr />
<div align="center">
<input type="submit" name="saveInfo" value="Submit">
</div>
</fieldset>
</td>
</tr>
</table>
</form>
</body>
</html>
Share
Improve this question
edited Sep 15, 2011 at 20:26
Ravi
asked Sep 15, 2011 at 20:14
RaviRavi
131 gold badge1 silver badge3 bronze badges
1 Answer
Reset to default 3You need to let your JSP print the following line of JavaScript whenever the URL has been received:
<script>window.open('<%= myUrl%>', 'YOUR_WINDOW_NAME');</script>
This way JS will open a new window/tab.
Unrelated to the concrete question, putting Java code inside JSP like that is a poor practice. Be warned!
本文标签: javascripthow to open a new window from a JSP fileStack Overflow
版权声明:本文标题:javascript - how to open a new window from a JSP file? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744174949a2593954.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论