ModelDrivenを使用するプログラムを作成しています。
http://codezine.jp/article/detail/4060?p=2
こちらのサイトを参考に作成しているのですが、
テキストフィールドに値を入力し、登録ボタンを押しても次の画面では変数に値が入っていない状態になっていて、
変数の値を表示できません。
以下ソースコードを記載します。
#web.xml
<?xml version="1.0" encoding="UTF-8"?> <web-app id="WebApp_9" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"> <display-name>BooksSample</display-name> <filter> <filter-name>struts2</filter-name> <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class> </filter> <filter-mapping> <filter-name>struts2</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> </web-app>
#struts.xml
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd"> <struts> <constant name="struts.enable.DynamicMethodInvocation" value="false" /> <constant name="struts.devMode" value="false" /> </struts>
#index.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>Hello!Project</title> </head> <body> <a href="books.action">sumple</a><br /> </body> </html>
#BooksAction.java
package books.action; import org.apache.struts2.convention.annotation.Action; import org.apache.struts2.convention.annotation.Result; import com.opensymphony.xwork2.ActionSupport; import com.opensymphony.xwork2.ModelDriven; public class BooksAction extends ActionSupport implements ModelDriven<BooksModel>{ private BooksModel model = new BooksModel(); @Override public BooksModel getModel() { return model; } @Action( value = "/books", results = { @Result(name = "success", location = "booksInput1.jsp") } ) public String execute() throws Exception { return "success"; } @Action( value = "/result", results = { @Result(name = "success", location = "booksResult1.jsp") } ) public String result() throws Exception { return "success"; } @Action( value = "/register", results = { @Result(name = "success", location = "booksRegister.jsp") } ) public String register() throws Exception { return "success"; } }
#BooksModel.java
package books.action; import java.io.Serializable; public class BooksModel implements Serializable{ private String isbn; // ISBN private String title; // 書名 private String author; // 作者名 public String getIsbn() { return isbn; } public void setIsbn(String isbn) { this.isbn = isbn; } public String getTitle() { return title; } public void setTitle(String title) { this.title = title; } public String getAuthor() { return author; } public void setAuthor(String author) { this.author = author; } }
#booksInput1.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>Input</title></head> <body> <s:textfield name="title" label="書名" /><br/> <s:textfield name="author" label="著者" /><br/> <s:textfield name="isbn" label="ISBN" /><br/> <a href="<s:url action="result"/>">登録</a> <s:debug /> </body> </html>
#booksResult1.jsp
<%@ page language="java" contentType="text/html; charset=Windows-31J" pageEncoding="Windows-31J"%> <%@ taglib prefix="s" uri="/struts-tags" %> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>確認</title> </head> <body> <s:property value="title" /><br/> <s:property value="author" /><br/> <s:property value="isbn" /><br/> <a href="<s:url action="register"/>">登録実行</a> <s:debug /> </body>
booksInput.jspの画面で値を入力し、登録を押して
booksResult.jspに画面遷移します。
その際に入力された値を表示させたいのですが、値が消えてしまって表示できません。
原因は何でしょうか。
回答1件
あなたの回答
tips
プレビュー