###前提・実現したいこと
JavaScriptを用いて画面遷移せず表示を切り替えて、
JSPにサーブレットの結果を反映させたいです。
理想の流れは下記の通りです。
1./home.jspからサーブレットにPOST送信
2./サーブレットの結果を/testA.jsp
(/home.jspの<div id="site-reading"></div>にtestAを読み込み表示切替しURLを/testA.jspに変更)
に反映
###発生している問題・エラーメッセージ
URL変更は必要不可欠ではありませんが、
サーブレットの結果を表示切替したJSPに読み込ませることができず手が止まってしまいました。
ご助言お願い致します。
###該当のソースコード
home.jsp <body> <div class="wrapper"> <div class='sidebar'> <ul id="watch" class="nav"> <li> <form method="post" name="my_form1" action="/test"> </form> <a onClick="change()">送信</a> </li> </ul> </div> <div class="content"> <div id="site-reading"></div> </div> </div> </body>
testA.jsp <body> <div id="test"> <h1 class="bg-primary">testA</h1><br> <h3 class="center-block">完了</h3> </div> </body>
javascript
1function change(){ 2 document.my_form1.submit(); 3 $("#site-reading").load("testA.jsp #test"); 4}
java
1test.java 2protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 3 try { 4 RequestDispatcher rd = null; 5 HttpSession session = request.getSession(); 6 session.setAttribute("hello", "hello"); 7 rd = getServletConfig().getServletContext().getRequestDispatcher("testA.jsp"); 8 rd.forward(request, response); 9 }catch(Exception e){ 10 }
回答1件
あなたの回答
tips
プレビュー