■実現したいこと
strtus2でindex.jspにて入力した値をサープレットを仲介してpage1.jspに表示させたい。
現在Javaの勉強を独学で行っているものです。
フレームワーク Struts2を使用して入力した値の表示をさせたく勉強しております。
■質問したいこと
以下の構成でプログラムを作成しております、
名前の受け渡し表示は出来るのですが。
idの受け渡し表示が出来ません。```ここに言語を入力
コード
どこか記述が間違っているのでしょうか? 皆様の知恵をお貸しください。 ■環境 ・Windows10 ・Struts2 2.5.10 ・tomcat 8.5 ・Eclipse oxygen で行っています。 やりたい流れとしては 【index.jsp】で「name」に名前、「id」にIDを入力. 【myuAction.java】を仲介して【page1.jsp】に「name」,「id」のデータを送信 【page1.jsp】にて受けとり、表示。 今後としてはDBを使用して、入力されたIDがDBに登録されているIDと一致するか判別する記述を追加する予定です。 ■【hori】動的webプロジェクト作成 ■【index.jsp】作成 <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Insert title here</title> </head> <body> <form action="ho"> あなたの名前とIDを入力してください 名前:<input type ="text" name="name"> ID:<input type="text" name="id" value=99> <input type="submit" value="ok"> </form> </body> </html> ■【ho.myuAction.java】作成 package ho; public class myuAction { private String name; private String id; public String execute() throws Exception{ return "success"; } public String getid() { return id; } public void setid(String id) { this.id=id; } public String getName() { return name; } public void setName(String name) { this.name=name; } } ■【page1.jsp】作成 <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@taglib prefix="s" uri="/struts-tags" %> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Insert title here</title> </head> <body> <s:property value="name"/> さんのIDは <s:property value="id"/> です。 </body> </html> ■【struts.xml】作成 <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" "http://struts.apache.org/dtds/struts-2.0.dtd"> <struts> <constant name = "struts.devMode" value = "true" /> <package name = "hori" extends = "struts-default"> <action name = "ho" class = "ho.myuAction" method = "execute"> <result name ="success">/page1.jsp</result> </action> </package> </struts> ■【web.xml】作成 <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1"> <display-name>hori</display-name> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> <filter> <filter-name>struts2</filter-name> <filter-class>org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter</filter-class> </filter> <filter-mapping> <filter-name>struts2</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> </web-app> ------------------------------------------------------------------------------------------------------------------------- 誰かにプログラミングの質問をしたことが無いので、もし足りない情報などがあれば伝えて頂ければ幸いです。 よろしくお願い致します。 追記、【struts.xml】の内容が間違っていたため修正致しました。

回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/06/12 12:40