JSPの教本のサンプルを見ながら記述しておりますが、
想定している動作になりません。
search.jspのテキストボックスに検索対象の文字列を入力して
ボタン押下後、redirect.jspで対象のURLにリダイレクトする
という処理を行いたいです。
◆search.jsp
<%@ page pageEncoding="UTF-8" %> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>検索エンジンの活用</title> </head> <body> <h1 style="color:white; background-color:#525D56; font-size:22px;"> 検索エンジンの活用</h1> <form method="GET" action="redirect.jsp"> <table border="0"> <tr> <th>検索ワード:</th> <td><input type="text" name="keywd" size=20 /></td> <td> <select name="eng"> <option value="Y">Yahoo!</option> <option value="G">Google</option> </select> </tr> <tr> <td colspan="2"><input type="submit" value="検索"/></td> </table> </form> </body> </html>
◆redirect.jsp
<%@ page pageEncoding="UTF-8" %> <c:choose> <c:when test="${param['eng'] == 'Y'}"> <c:out value="${param['keywd']}" /> <c:redirect url="https://search.yahoo.co.jp/bin/search"> <c:param name="p" value="${param['keywd']}"/> </c:redirect> </c:when> <c:when test="${param['eng'] == 'G'}"> <c:redirect url="https://www.google.co.jp/webhp"> <c:param name="q" value="${param['keywd']}"/> </c:redirect> </c:when> <c:otherwise> <div style="color:Red";>検索エンジンの指定が間違っています</div> </c:otherwise> </c:choose>
上記を実行すると、
開発者ツール上(応答ヘッダ)でc:when test=trueが返ってきているにも関わらず
<c:otherwise>の「検索エンジンの指定が間違っています」が
画面に表示されてしまうだけでリダイレクトが実行されません。
参考サイトからも<c:when>でtest=trueとなれば、
<c:otherwise>は通らないようでした。
http://tag.main.jp/cwhen.html
Eclipse上で実行しておりますが、何か別の設定が必要なのでしょうか。
もしくは、ソースに問題があるのでしょうか。
初歩的な質問で申し訳ございませんがよろしくお願いします。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/02/08 14:08
2017/02/08 16:25