質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.46%
Java

Javaは、1995年にサン・マイクロシステムズが開発したプログラミング言語です。表記法はC言語に似ていますが、既存のプログラミング言語の短所を踏まえていちから設計されており、最初からオブジェクト指向性を備えてデザインされています。セキュリティ面が強力であることや、ネットワーク環境での利用に向いていることが特徴です。Javaで作られたソフトウェアは基本的にいかなるプラットフォームでも作動します。

JavaScript

JavaScriptは、プログラミング言語のひとつです。ネットスケープコミュニケーションズで開発されました。 開発当初はLiveScriptと呼ばれていましたが、業務提携していたサン・マイクロシステムズが開発したJavaが脚光を浴びていたことから、JavaScriptと改名されました。 動きのあるWebページを作ることを目的に開発されたもので、主要なWebブラウザのほとんどに搭載されています。

Eclipse

Eclipseは、IBM社で開発された統合開発環境のひとつです。2001年11月にオープンソース化されました。 たくさんのプラグインがあり自由に機能を追加をすることができるため、開発ツールにおける共通プラットフォームとして位置づけられています。 Eclipse自体は、Javaで実装されています。

Q&A

解決済

1回答

2875閲覧

window.openでactionクラスを実行クラスを実行することはできますか?

Y.Mamoru

総合スコア47

Java

Javaは、1995年にサン・マイクロシステムズが開発したプログラミング言語です。表記法はC言語に似ていますが、既存のプログラミング言語の短所を踏まえていちから設計されており、最初からオブジェクト指向性を備えてデザインされています。セキュリティ面が強力であることや、ネットワーク環境での利用に向いていることが特徴です。Javaで作られたソフトウェアは基本的にいかなるプラットフォームでも作動します。

JavaScript

JavaScriptは、プログラミング言語のひとつです。ネットスケープコミュニケーションズで開発されました。 開発当初はLiveScriptと呼ばれていましたが、業務提携していたサン・マイクロシステムズが開発したJavaが脚光を浴びていたことから、JavaScriptと改名されました。 動きのあるWebページを作ることを目的に開発されたもので、主要なWebブラウザのほとんどに搭載されています。

Eclipse

Eclipseは、IBM社で開発された統合開発環境のひとつです。2001年11月にオープンソース化されました。 たくさんのプラグインがあり自由に機能を追加をすることができるため、開発ツールにおける共通プラットフォームとして位置づけられています。 Eclipse自体は、Javaで実装されています。

0グッド

2クリップ

投稿2020/11/12 09:42

編集2020/11/12 10:02

〇やりたいこと
リンクをクリックしたときに、別の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

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

ベストアンサー

window.open('/userlist'); ですと、実際にリクエストしているURLが、

おそらくhttp://********:8081/userlist になっているかと思いますので、コンテキストパスを追加するか、(あまり良い書き方ではないですが)相対パスに変更すると良いでしょう。

HTML

1<script> 2function click_link(){ 3 window.open('<%= request.getContextPath() %>/userlist');//予定ではここでアクションクラスを実行 4} 5</script>

投稿2020/11/12 13:21

A-pZ

総合スコア12011

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

Y.Mamoru

2020/11/13 00:28

ありがとうございます!! <%= request.getContextPath() %>/userlist.do で実行すると、actionクラスが実行されました(^o^)
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.46%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問