〇やりたいこと
リンクをクリックしたときに、別のactionクラスを実行するようにjavascriptを組みたいです。
下記のサイトの中で、『window.open('~.do')』でアクションクラスを実行できるようなことを見つけました。
https://www.atmarkit.co.jp/bbs/phpBB/viewtopic.php?topic=28292&forum=12
これを基にしてコーディングしたのですが、動かないです(><)
自分の書き方が悪いのか、そもそも方法から違うのか。
アドバイスをお願いします。
jsp
1<%@ page language="java" contentType="text/html; charset=UTF-8" 2 pageEncoding="UTF-8"%> 3<%@ taglib uri = "http://struts.apache.org/tags-html" prefix = "html" %> 4 5<!DOCTYPE html> 6<html:html> 7 <head> 8 <meta charset="UTF-8"> 9 <title>Insert title here</title> 10 <link rel = "stylesheet" href = "http://localhost:8081/Attendance_Apli/CSS/AttendanceCSS.css"> 11 //ここでアクションクラスを実行する内容を書きたい 12 <script> 13 function click_link(){ 14 alert("pass");//アラートは問題なく実行される 15 window.open('/userlist');//予定ではここでアクションクラスを実行 16 widow.close(); 17 //alert(list(0)); 18 } 19 </script> 20 </head> 21 <body id = "top_body"> 22 <div id = "top_mainDiv"> 23 <% String msg = (String)request.getAttribute("msg"); 24 if(msg != null){ 25 %> 26 <p><% out.println(msg); %></p><br> 27 <% } %> 28 <h1>勤怠管理</h1> 29 <br> 30 <html:form action = "/attendance"> 31 <div id = "top_submit"> 32 <button type = "submit" name = "attendance" value = "I" id = "top_attend" >出勤</button> 33 <button type = "submit" name = "attendance" value = "O" id = "top_attend">退勤</button> 34 </div> 35 </html:form> 36 37 <br> 38 <a href = "#" onClick = "click_link();">ユーザー一覧だよ</a> 39 <html:link action = "/userlist" >ユーザー一覧</html:link>//★★このリンクでjavascirptを実行する 40 <br> 41 <a href = "http://localhost:8081/Attendance_Apli/JSP/list/MonthAttendance.jsp" id = "top_a">勤怠一覧(月次)</a> 42 <br> 43 <br> 44 <div id = "top_submit"> 45 <html:form action = "/logout"> 46 <html:submit property = "logout" value = "ログアウト"/> 47 </html:form> 48 </div> 49 </div> 50 </body> 51</html:html>
sturts-configの設定と合っていないのか、とも考えているので載せておきます。
strutsconfig
1<?xml version = "1.0" encoding = "ISO-8859-1"?> 2<!DOCTYPE struts-config PUBLIC 3 "-//Apache Software Foundation .. DTD Struts Configuration 1.1//EN" 4 "http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd"> 5 6<struts-config> 7 8 <form-beans> 9 <form-bean 10 name = "UserActionForm" 11 type = "model.UserActionForm"/> 12 <form-bean 13 name = "LoopListForm" 14 type = "model.LoopListForm"/> 15 </form-beans> 16 17 <action-mappings> 18 <action 19 path = "/login" 20 type = "database.LoginAction" 21 name = "UserActionForm" 22 scope = "session"> 23 <forward name = "toTop" path = "/JSP/top/Top.jsp"/> 24 <forward name = "LoginError" path = "/JSP/error/LoginError.jsp"/> 25 </action> 26 27 <action 28 path = "/userlist" 29 type = "list.UserListAction" 30 name = "UserActionForm" 31 scope = "session"> 32 <forward name = "toUserList" path = "/JSP/list/UserList.jsp"/> 33 <forward name = "error" path = "/JSP/error/Error.jsp"/> 34 <forward name = "toTop" path = "/JSP/top/Top.jsp"/> 35 </action> 36 37 <action 38 path = "/regist" 39 type = "regist.RegistAction" 40 name = "UserActionForm" 41 scope = "session"> 42 <forward name = "registDone" path = "/JSP/regist/RegistDone.jsp"/> 43 <forward name = "registError" path = "/JSP/error/RegistError.jsp"/> 44 </action> 45 46 <action 47 path = "/action" 48 type = "update.PreUpdateAction" 49 name = "UserActionForm" 50 scope = "session"> 51 <forward name = "toUpdate" path = "/JSP/update/UserUpdate.jsp"/> 52 <forward name = "toDelete" path = "/JSP/delete/UserDelete.jsp"/> 53 <forward name = "error" path = "/JSP/error/Error.jsp"/> 54 </action> 55 56 <action 57 path = "/update" 58 type = "update.UpdateAction" 59 name = "UserActionForm" 60 scope = "session"> 61 <forward name = "updateDone" path = "/JSP/update/UpdateDone.jsp"/> 62 <forward name = "updateError" path = "/JSP/error/UpdateError.jsp"/> 63 </action> 64 65 <action 66 path = "/delete" 67 type = "delete.DeleteAction" 68 name = "UserActionForm" 69 scope = "session"> 70 <forward name = "deleteDone" path = "/JSP/delete/DeleteDone.jsp"/> 71 <forward name = "deleteError" path = "/JSP/error/DeleteError.jsp"/> 72 </action> 73 74 <action 75 path = "/logout" 76 type = "database.LogoutAction" 77 name = "UserActionForm" 78 scope = "session"> 79 <forward name = "logout" path = "/JSP/logout/Logout.jsp"/> 80 </action> 81 82 <action 83 path = "/attendance" 84 type = "attendance.Attendance" 85 name = "UserActionForm" 86 scope = "session"> 87 <forward name = "toTOP" path = "/JSP/top/Top.jsp"/> 88 <forward name = "error" path = "/JSP/error/Error.jsp"/> 89 </action> 90 91 <action 92 path = "/attendList" 93 type = "list.AttendanceList" 94 name = "UserActionForm" 95 scope = "session"> 96 <forward name = "toMonthList" path = "/JSP/list/MonthAttendance.jsp"/> 97 <forward name = "error" path = "/JSP/error/Error.jsp"/> 98 </action> 99 </action-mappings> 100 101 102</struts-config> 103 104
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2020/11/13 00:28