検索アプリを作っています。
機能しないものの、エラーメッセージが出ないで困っています。
デバッグをしたところ、listに配列が入っていないようなのですが、なぜなのかよくわからないです。
DBにアクセスするファイルを作ったところ、DB自体にはアクセスできているようです。
画面上の情報としては、Bitmresult.jspに、itmの値のみ出力されており、ほかの変数が出力されません。
足りない情報ありましたらご連絡ください。
BitmForm.java
java
1package form; 2 3import org.apache.struts.action.ActionForm; 4 5public class BitmForm extends ActionForm{ 6 7 private String itm = ""; 8 private String inm = ""; 9 private String kit = ""; 10 private String cit = ""; 11 private String sec = ""; 12 13 public String getItm() { 14 return itm; 15 } 16 public void setItm(String itm) { 17 this.itm = itm; 18 } 19 public String getInm() { 20 return inm; 21 } 22 public void setInm(String inm) { 23 this.inm = inm; 24 } 25 public String getKit() { 26 return kit; 27 } 28 public void setKit(String kit) { 29 this.kit = kit; 30 } 31 public String getCit() { 32 return cit; 33 } 34 public void setCit(String cit) { 35 this.cit = cit; 36 } 37 public String getSec() { 38 return sec; 39 } 40 public void setSec(String sec) { 41 this.sec = sec; 42 } 43} 44
BitmSearch.jsp
jsp
1<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> 2<%@ taglib uri="/tags/struts-html" prefix="html" %> 3<%@ taglib uri="/tags/struts-bean" prefix="bean" %> 4<%@ taglib uri="/tags/struts-logic" prefix="logic" %> 5 6<!DOCTYPE html> 7<html:html> 8<head> 9<meta charset="UTF-8"> 10<title>Insert title here</title> 11</head> 12<body> 13 <h3>品目コード検索</h3> 14 <html:form action="/BitmResult" > 15 <html:text name="BitmForm" property="itm" /> 16 <html:submit value="検索" /> 17 </html:form> 18</body> 19</html:html>
BitmResult.jsp
jsp
1<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> 2<%@ taglib uri="/tags/struts-html" prefix="html" %> 3<%@ taglib uri="/tags/struts-bean" prefix="bean" %> 4<%@ taglib uri="/tags/struts-logic" prefix="logic" %> 5 6<!DOCTYPE html> 7<html:html> 8<head> 9<meta charset="UTF-8"> 10<title>Insert title here</title> 11</head> 12<body> 13 <h3>品目コード検索結果</h3> 14 <table> 15 <tr> 16 <th>品目コード</th> 17 <th>品名</th> 18 <th>品目タイプ</th> 19 <th>品目グループ</th> 20 <th>部門</th> 21 </tr> 22 <tr> 23 <td><bean:write name="BitmForm" property="itm" /></td> 24 <td><bean:write name="BitmForm" property="inm" /></td> 25 <td><bean:write name="BitmForm" property="kit" /></td> 26 <td><bean:write name="BitmForm" property="cit" /></td> 27 <td><bean:write name="BitmForm" property="sec" /></td> 28 </tr> 29 </table> 30</body> 31</html:html> 32
BitmAction.java
java
1package action; 2 3import java.sql.Connection; 4import java.sql.SQLException; 5import java.util.ArrayList; 6 7import javax.naming.NamingException; 8import javax.servlet.http.HttpServletRequest; 9import javax.servlet.http.HttpServletResponse; 10 11import org.apache.struts.action.Action; 12import org.apache.struts.action.ActionForm; 13import org.apache.struts.action.ActionForward; 14import org.apache.struts.action.ActionMapping; 15 16import dao.Bitm; 17import dao.DB400Connection; 18import form.BitmForm; 19 20public class BitmAction extends Action{ 21 public 22 ActionForward execute( 23 ActionMapping mapping, 24 ActionForm form, 25 HttpServletRequest request, 26 HttpServletResponse response) 27 28 throws 29 SQLException, 30 NamingException, 31 IllegalAccessException, 32 java.lang.reflect.InvocationTargetException, 33 Exception{ 34 35 request.setCharacterEncoding("UTF-8"); 36 String item = request.getParameter("itm"); 37 38 DB400Connection db400connection = new DB400Connection(); 39 Connection conn = db400connection.getConnection(); 40 41 Bitm bitm = new Bitm(); 42 ArrayList<BitmForm> list = bitm.LoadData1(conn, item); 43 44 request.setAttribute("BitmForm", list); 45 46 return (mapping.findForward("success")); 47 } 48} 49
Bitm.java
java
1package dao; 2 3import java.lang.reflect.InvocationTargetException; 4import java.sql.Connection; 5import java.sql.PreparedStatement; 6import java.sql.ResultSet; 7import java.sql.SQLException; 8import java.util.ArrayList; 9 10import org.apache.commons.beanutils.BeanUtils; 11 12import form.BitmForm; 13 14public class Bitm { 15 16 public ArrayList<BitmForm> LoadData1(Connection conn, String item) 17 throws SQLException, IllegalAccessException, InvocationTargetException{ 18 19 String sql 20 = "SELECT ITMITM,ITMINM,ITMKIT,ITMCIT,ITMSEC " + 21 " FROM LIBFILE.BITM1M00 " + 22 " WHERE ITMITM=?" ; 23 24 PreparedStatement pStmt = conn.prepareStatement(sql); 25 pStmt.setString(1, item); 26 ResultSet rs = pStmt.executeQuery(); 27 28 if(rs.next()) { 29 BitmForm bitmform = new BitmForm(); 30 BeanUtils.setProperty(bitmform, "itm", rs.getString("ITMITM")); 31 BeanUtils.setProperty(bitmform, "inm", rs.getString("ITMINM")); 32 BeanUtils.setProperty(bitmform, "kit", rs.getString("ITMKIT")); 33 BeanUtils.setProperty(bitmform, "cit", rs.getString("ITMCIT")); 34 BeanUtils.setProperty(bitmform, "sec", rs.getString("ITMSEC")); 35 } 36 return null; 37 } 38} 39
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/12/26 07:43
2019/12/26 13:02