1
jspファイルから新しいウィンドウを開く必要があります。 JSPファイルでは、ユーザーからの入力を受け取り、URLを文字列として返すjavaメソッドに引数として送信します。私は新しいウィンドウでこれを開く必要があります。それ、どうやったら出来るの?以下は、参考のために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
はい私です。私はそれがそれを行う最良の方法ではないことを知っています。私はまた、応答を正常に戻しています。私は新しいウィンドウで文字列のURLを開く方法を知らない – Ravi