STRUTSで選択したものを指定した文字で出力することで困っています
STRUTS-confirm.xml
<form-beans> <form-bean name="InputForm" type="infoForm"> </form-bean> </form-beans> <action path="/input" type="action.action" name="InputForm" scope="request"> <forward name="success" path="/pages/Input.jsp"/> </action> <action path="/confirm" type="action.Confirm" name="InputForm" scope="request"> <forward name="success" path="/pages/Confirm.jsp"/> </action>
こちらは大丈夫かなと思っています
アクションフォームクラス
/** *各コードから名前を取得 */ public class infoForm extends ActionForm { // -------フィールド-------------------------------- /** 選択された性別*/ private String gender; /** 選択された性別コード*/ private String genderCode; /** 選択されたキャリアコード*/ private String[] CareerCode; /** 選択されたキャリア*/ private String[] Career; // setter/getter-------------------- public void setGender(String gender) { this.gender = gender; } public String getGender() { return gender; } public void setGenderCode(String genderCode) { this.genderCode = genderCode; } public String getGenderCode() { return genderCode; } public void setCareerCode(String[] CareerCode) { this.CareerCode = CareerCode; } /** * キャリアを返します。 * @return subjectCode */ public String[] getCareerCode() { return CareerCode; } public void setCareer(String[] Career) { this.Career = Career; } public String[] getCareer() { return Career; } }
こちらはsetter getterを用意
入力JSP
<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>生徒情報入力</title> </head> <body> <html:form action="/confirm"> 性別を選んでください <html:radio name="InputForm" property="genderCode" value="M"/>男性 <html:radio name="InputForm" property="genderCode" value="F"/>女性 <br> キャリアを選んでください。 <html:multibox name="InputForm" property="CareerCode" value="d" />ドコモ <html:multibox name="InputForm" property="CareerCode" value="a" />AU <html:multibox name="InputForm" property="CareerCode" value="s" />ソフトバンク <br> <html:submit property="submit" value="送信"/> <html:reset value="リセット"/> </html:form> </body> </html>
ここで性別は「男性」か「女性」を出力
キャリアは1つ以上選んで選んだキャリアの文字を出力したいんですがvalueは変えず維持したいんです
出力JSP
<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>確認画面</title> </head> <body> <form name="Customers" action="input.do" method = "post"> 性別:<bean:write name="InputForm" property="gender" scope="request"/><br> <html:hidden name="InputForm" property="genderCode" /> キャリア:<logic:iterate id="code" name="InputForm" property="Career" scope="request"> <bean:write name="code"/> <input type="hidden" name="CareerCode" value="<bean:write name="code"/>"> </logic:iterate> <br> <input type="submit" value="戻る"> </form> </body> </html>
出力JSPはこんな感じにしています。
action.Confirmのアクションクラス
public class Confirm extends Action { public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest req, HttpServletResponse res) { //フォーム作成 infoForm inputForm = (infoForm) form; String ChoiceGender = inputForm.getGenderCode(); if(ChoiceGender.equals("M")) { inputForm.setGender("男性"); } else { inputForm.setGender("女性"); } String[] ca = inputForm.getSubjectCode(); for(int i = 0; i < ca.length; i++) { inputForm.setSubjectName(ca[i]); } return (mapping.findForward("success")); } }
という感じで作成途中ですが性別は選んだほうを予め用意した別の変数で値を設定して出力時は男性(女性)でだしてVALUEはM(F)で維持できます
キャリアも同様に行いたいのですが配列で用意されているため途中で型が合わないと書かれてできない状態です
選んだキャリアを出力して出力のJSP側でのキャリアのVALUEはMULTIBOXで入力したVALUEのまま維持したいのですがどのようにおこなえばよろしいのでしょうか
どなたかお願いします。
ちなみにもしできたらこのあと性別と同じように別の変数で値を設定します。
ちなみにaction.actionクラスは
public class action extends Action { public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest req, HttpServletResponse res) { return (mapping.findForward("success")); } }
です。
importは省略しています。
あなたの回答
tips
プレビュー