• ベストアンサー

strutsプログラミングでの疑問

strutsプログラムをしているところで質問です。 javascriptでbuttonを押すことで、actionを走らせるコーディングをご存知の方がおられましたら教えて頂けないでしょうか。 以下にコーディングとエラーメッセージを載せておきます。 コーディング <script language="JavaScript"> function jump{ document.MainForm.action="StrutsSample.do"; document.MainForm.submit(); } </Script> <form method="post" action="#" name="MainForm"> <input type="button" value="追加" onclick="jump()"> </form> エラーメッセージ HTTPステータス 500 javax.servlet.ServletException: Cannot find bean under name org.apache.struts.taglib.html.BEAN

質問者が選んだベストアンサー

  • ベストアンサー
noname#18558
noname#18558
回答No.1

javascriptからActionを実行する記述はあってると思いますが、エラーは別の原因かと思います。 おそらく、JSPでエラーがでてるのではないでしょうか。

liony_2003
質問者

お礼

どうもありがとうございます。 上記のコードは抜粋ですので、再度JSPのコードを確認しようと思います。

その他の回答 (1)

  • shiro-joe
  • ベストアンサー率22% (15/66)
回答No.2

"Cannot find bean under name "とあるので、JSPがBeanを見つけられないとかそういった感じのエラーに思えます。 JSPでどのBeanからデータを表示するか記述しますが、そのBean名とStruts-configで設定したBean名があっていないとか、Actionでスコープに保存する時の名前と一致していないとか…。

liony_2003
質問者

お礼

どうもありがとうございます。 なるほど、初歩的なコーディングミスではないかということですね。 再度調べてみます。

関連するQ&A

  • strutsプログラミングでJAVASCRIPTの設定

    Strutsプログラムで、JSPに下記コーディング(抜粋)をして実行すると、 HTTPステータス 500 - javax.servlet.ServletException: Cannot retrieve mapping for action /# というエラーが表示されます。 この原因と、解決策を教えて頂けないでしょうか? 目的は、 「JAVASCRIPTを使って、1つのformに複数のボタンをつくり、それぞれ異なるactionを実行させたい」 わけです。 エラーメッセージから、主な原因はaction="#"にしていることだと思うのですが、どう変えればいいかが分かりません。 <script language="JavaScript">  function jump_1(){   document.MainForm.action="pages/StrutsSample_1.do";   document.MainForm.submit();  }  function jump_2(){   document.MainForm.action="StrutsSample_2.do";   document.MainForm.submit();  } </Script> <html:form method="post" action="#" >  <html:button property="MainForm" value="追加" onclick="jump_1()" />  <html:button property="MainForm" value="修正" onclick="jump_2()" />  <html:radio property="checked" value="1" />  <logic:iterate id="itm" name="key">   <bean:write name="itm" />  </logic:iterate><br> </html:form>

    • ベストアンサー
    • Java
  • strutsの画面遷移無しでtextの値をボタンで操作したいのですが・・・

    最近strutsを始めた者です。よろしくお願いします。 画面上でボタンを押すとtextに表示中の値に”さん”を付けて textに再表示(画面遷移ナシ)されるといった 動作をさせたいのですが上手くいきません。 javascriptの関数がおかしいとおもうのですが・・・ 以下にソースを付けますのでどなたかご教授願います。 <%@page contentType="text/html; charset=Shift_JIS" %> <%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %> <%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %> <html:html locale="true" > <BODY> <html:form action="/HelloWorld" > <SCRIPT LANGUAGE=javascript> <!-- function addItem( obj1 ){ var txt = obj1; if ( txt.value == "" ) return; var test = txt.value + "さん"; obj1.value = test; } --> </SCRIPT> <bean:message key="greeting" /><BR> お名前をどうぞ。 <BR><html:text property="name" /><BR> <html:button property="button" value="textの値にさんをつける" onclick="addItem(this.form.name,);" /> </html:form> </BODY> </html:html>

  • strutsでコンパイラ

    strutsでコンパイラができません struts-confing <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.2//EN" "http://struts.apache.org/dtds/struts-config_1_2.dtd"> <struts-config> <form-beans> <form-bean name="Update" type="action.form.Update"/> <form-bean name="kensaku2" type="action.form.kensaku2"/> </form-beans> <!-- アクションの定義 --> <action-mappings> <!-- Form情報をUpdateとして、action.AccountFormクラスをアクションとして指定する --> <!-- Form情報はリクエストスコープに格納される --> <action name="HelloWorldForm" type="action.AccountForm" path="/Update" scope="request" > <!-- アクションの遷移先として論理名をhello ファイルパスを/webJSP/index.jspとする --> <forward name="Update" path="/webJSP/index.jsp" /> </action> </action-mappings> <message-resources parameter="ApplicationResource" /> </struts-config> index.jsp <%@page contentType = "text/html; charset=Shift_JIS"%> <%@page import= "java.util.List,websample.Account"%> <%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %> <%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %> <html:html> <head> <title>一覧画面</title> </head> <body> <!-- HTMLのFROMタグに変換される --> <html:form method="POST" action="tuika1" target="_blank "> <div><font size="6" ><strong>顧客一覧画面</strong></font></div> <input type="submit" value="追加" name="insert"> </html:form> <form method="POST" action="kousin11" target="_blank "> <input type="submit" value="更新" name="update"> </html:form> <script type="text/javascript"> <!-- function disp(){ // 「OK」時の処理開始 + 確認ダイアログの表示 if(window.confirm('削除しますか')){ location.href = "index.jsp"; // index.jsp へジャンプ } // 「OK」時の処理終了 // 「キャンセル」時の処理開始 else{ window.alert('キャンセルされました'); // 警告ダイアログを表示 } // 「キャンセル」時の処理終了 } // --> </script> <html:form method="POST" action="Update"> <input type="submit" value="削除" name="delete" onClick="disp()"></p> <table border="1"> <tr> <TH>コード <TH>名称 <TH>住所 <TH>電話 <TH>メール <% List list = (List)request.getAttribute("list"); for(int i=0; i<list.size(); i++){ Account account = (Account)list.get(i); %> <tr> <td><%=account.getid()%> <td><%=account.getname()%> <td><%=account.getaddress()%> <td><%=account.getdenwa()%> <td><%=account.getmail()%> <td><input type="radio" name="radio" value="<%=account.getid()%>" > <% } %> </table> </html:form> </body> </html:html>

  • strutsのApplicationResource.propertiesの文字化けについて

    表題の通りstrutsのApplicationResource.propertiesを利用した部分が文字化けしてしまいます 以下にファイルの詳細を記述します。 JSPファイル <%@page contentType="text/html; charset=Shift_JIS" %> <%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html"%> <%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean"%> <html:html> <BODY> <html:form action="/HelloWorld" > <bean:message key="greeting" /><BR> お名前をどうぞ。<BR><html:text property="name" /><BR> <html:submit> <bean:message key="greeting" /> </html:submit> </html:form> </BODY> </html:html> ApplicationResource.propertiesのファイル greeting=こんにちは welcome=ようこそ 状況 「お名前をどうぞ」は正しく表示 keyのgreetingは?±????????と表示 以上のような状態となってしまいます。どなたか解決策をご存じの方はご教授ください

    • ベストアンサー
    • Java
  • strutsで画面遷移

    お世話になります。struts初心者です。 test1.jspから、リンクをクリックしたら、次のページ(download.jsp)へ遷移させたいのですが、「ページが見つかりません」となってしまいます。 以下のようなソースコードにしています。 どこがおかしいのでしょうか・・・・情報少ないでしょうか。わかる方いらっしゃいましたら、おしえてください。 https://xxxxx/test/test1.jsp  ↓リンククリックで下記URLになり「ページが見つかりません」 https://xxxxx/login/menu.do ------------------------------------------------------- test1.jsp ------------------------------------------------------- <html:html> <head> <script language="JavaScript"> <!-- function gonext(){ document.menuForm.menuOperation.value ="download"; document.menuForm.submit(); } --> </script> </head> <body> <html:form action="/login/menu"> <html:hidden property="menuOperation"/> <A href="javascript:gonext()"> go next </A> </html:form> </body> </html:html> ------------------------------------------------------- struts-config.xml ------------------------------------------------------- <form-beans> <form-bean name="menuForm" type="xxx.login.CMenuActionForm"/> </form-beans> <action-mappings> <action path="/login/menu" type="xxx.login.CMenuAction" name="menuForm" scope="request"> <forward name="download" path="/common/download.jsp"/> </action> </action-mappings> ------------------------------------------------------- CMenuAction.java ------------------------------------------------------- public class CMenuAction extends CxxxDLAction{ public ActionForward execute( ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { return mapping.findForward("download"); } } ------------------------------------------------------- CMenuActionForm.java ------------------------------------------------------- public class CMenuActionForm extends ActionForm{ String menuOperation; public String getmenuOperation() { return menuOperation; } public void setmenuOperation(String menuOperation) { this.menuOperation = menuOperation; } }

  • strutsプログラミングで、こんなことできますか?

    strutsプログラムで、一般にはsubmitボタン実行後にactionが走りますが、チェックボックスやラジオボタンにチェックを入れるとactionが走るようにはコーディングできるのでしょうか? ラジオボタンにチェックするたびに、チェックした情報データをFORMに格納aform.setName(data1)したいのです。

    • ベストアンサー
    • Java
  • 教えてください:strutsのhtml:formタグがjspに展開された状態の、actionの値について

    java初心者です。 どなたか教えていただけませんでしょうか? JAVAのstrutsを使用してソフトを作成しています。 JSPに記載した「<html:form action="/authentication" focus="id"> 」 との記述が、WEB(IE)に展開されたソースを見ると、「<form name="AuthenticationForm" method="post" action="/strutsTest/authentication">」 に変換されています。 action="/authentication"と記述しているにもかかわらず、 action="/strutsTest/authentication"と展開されているのですが /strutsTestが自動的に付与されているのは、なぜなのでしょうか? なにか設定するところがあるのでしょうか? ※struts-config.xmlに指定したpathと一致しない為、404NotFoundになるので自動設定しないように変更したいのです。 ちなみに環境は struts-1.3.10 Apache Tomcat 6.0.14 Server EclipsVersion: 3.4.2 pakage名:struts プロジェクト名:strutsTest struts-config.xmlの設定   <form-beans> <form-bean name="AuthenticationForm" type="struts.AuthenticationForm"/> </form-beans> <global-exceptions> </global-exceptions> <global-forwards> <forward name="fail" path="/login.jsp"/> </global-forwards> <action-mappings> <action path="/authentication" name="AuthenticationForm" type="struts.AuthenticationAction" scope="session"> <forward name="success" path="/welcome.jsp"/> <forward name="fail" path="/login.jsp"/> </action> </action-mappings> login.jsp <%@ page contentType="text/html; charset=Windows-31J" %> <%@ taglib uri="/tags/struts-bean" prefix="bean" %> <%@ taglib uri="/tags/struts-logic" prefix="logic" %> <%@ taglib uri="/tags/struts-html" prefix="html" %> <html:html> <head> <meta http-equiv="Content-Type" content="text/html; charset=Windows-31J"/> <title>ログイン画面</title> </head> <body> <html:errors/> ID・パスワードを入力してください。 <html:form action="/authentication" focus="id"> <html:text property="id" size="16"/> <br> <html:password property="pas" size="16" redisplay="false" /> <br> <html:submit property="submit" value="送信"/> <html:reset value="リセット"/> </html:form> </body> </html:html> 動作順は、login.jsp => AuthenticationAction.class => welcome.jsp です。 よろしくお願いします。

  • ☆Struts ActionServletの内部動作について

    Struts勉強中のものです。教えて下さい♪ struts-config.xmlより抜粋... <form-bean name="loginForm" type="jp.co.struts.LoginForm"/> <!----> <action-mappings> <!--Add action --> <action path="/login" name="loginForm" type="jp.co.struts.LoginAction"> <forward name="success" path="/jsp/loginSuccess.jsp"/> <forward name="error" path="/jsp/loginError.jsp"/> </action> </action-mappings> 以下URL画面の中段の画像の説明であるのですが、 (http://www.itmedia.co.jp/enterprise/0310/06/epn03_4.html) ActionServletは、struts-config.xmlを参照して、ActionFormクラスを処理した後にActionクラスを実行する内容の記載がありますが、内部的にはまず、Actionクラスを判別してから、nameで紐付けてActionFormクラスを判別しているのでしょうか?? 上記のstruts-config.xmlを例に具体的に言いますと。 まず、login.doが実行された場合、 <form-bean name="loginForm" type="jp.co.struts.LoginForm"/> には、path="/login" の属性がないので、まず、 <action path="/login" name="loginForm" type="jp.co.struts.LoginAction">を読み込んで、name属性とひもづく、form-beanのtype(type="jp.co.struts.LoginForm")に設定されたクラスを処理しているのでしょうか?? なぜ form-bean にpath属性を作って、login.doが実行された際に適切なform-beanを判別するようになっていないのかが疑問です・・・・ わかりずらい説明で申し訳ないですが。ご教授下さい。 また、このへんの説明が詳しく書いている本、サイト教えて下さい。 頑張ってStrutsを深く理解していきたいです♪

  • Struts 1.3 でbeanタグが認識されない

    Struts初心者です。 Struts1.3で以下のようなJSPを作成していますが、 "bean:write"のところで、"bean"に対応するtaglibディレクトリが存在しないかTLDファイルが見つかりません。 とエラーになります。 <%@ page contentType="text/html;charset=Windows-31J" %> <%@ taglib uri="http://struts.apache.org/tags-html" prefix="html" %> <%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %> ・ ・ ・ <html:html> <head> <title>○○○○○○○○</title> </head> <body> <h1>○○○○○○○○</h1> ●●●●<bean:write name="xxxx" property="id" />! </body> </html:html> "html"の方はエラーになりません。 ケアレスミスのような気がしていますので、どなたか教えていただけると嬉しいです。

  • コンパイラ struts

    フレームでコンパイラができません 助けてください top.html→menu.html、syouhin_kensaku.html,index.html menu.html(あ、い)(あ)を押したらhtmlはでますがjspが404がでます なぜでしょう struts-confing.xml <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.2//EN" "http://jakarta.apache.org.struts/dtds/struts-config_1_2.dtd"> <struts-config> <!-- データソースの設定 --> <date-sources> <!-- BasicDateSourseクラスを利用する --> <date-sourse typr="org.apache.commons.dbcp.BasicDateSourse"> <!-- JDBCドライバクラス名の設定 --> <set-property="driverClassName" value="com.mysql.jdbc.Driver"/> <!-- JDBCの接続文字列の設定 --> <set-propety propety="url" value="jdbc:mysql://localhost/struts?useUnicode=true&amp;characterEncoding=Windows-31J"/> <!-- MySQLのユーザーIDの設定 --> <set-propety propety="username" value="root"/> <!-- MySQLのパスワードの設定 --> <set-propety propety="passward" value="root"/> </date-sources> <!-- Form情報の定義 --> <form-beans> <form-bean name="AccountForm" type="action.form.AccountForm"/> </form-beans> <!-- アクションの定義 --> <action-mappings> <!-- Form情報をAccountFormとして、action.AccountFormクラスをアクションとして指定する --> <!-- Form情報はリクエストスコープに格納される --> <action name="Account" type="action.UpdateAction" path="/UpdateAction" scope="request" > <!-- アクションの遷移先として論理名をUpdate ファイルパスを/webJSP/index.jspとする --> <forward name="Update" path="/webJSP/index.jsp" /> </action> </action-mappings> <message-resources parameter="jp.co.jetsystem.message.MessageResources.properties"/> </struts-config>