1
我需要从jsp文件打开一个新窗口。在一个JSP文件中,我接受来自用户的输入,然后将其作为参数发送给一个java方法,该方法以字符串形式返回url。然后我需要在新窗口中打开它。我怎么做?以下是jsp文件(send_product.jsp)供您参考。如何从JSP文件打开新窗口?
<%@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>
但我想打开字符串myUrl中的url(该字符串捕获方法getUrl的返回值)。假设该方法返回www.google.com,我想在新窗口中打开google.com。 – Ravi
哦,你正在处理表单提交内部相同的JSP?我会更新答案。 – BalusC
是的,我是。我知道这不是最好的办法。我也成功回复了回复。我不知道如何在新窗口中打开字符串中的网址 – Ravi