求助,我的ArrayList值怎样才能输出在jsp页面中
这是一个在页面中输入id,然后点击提交按钮,在页面对应的文本框中显示查询的结果的程序,用的struts结构SyoukaiForm和SyoukaiVO内容相同:就是get,...
这是一个在页面中输入id,然后点击提交按钮,在页面对应的文本框中显示查询的结果的程序,用的struts结构
SyoukaiForm和SyoukaiVO内容相同:
就是get,和set各个字段
————————————————————————————————
SyoukaiAction内容如下:
public class SyoukaiAction extends Action
{
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) throws Exception
{
String target = "false";
SyoukaiForm syf = (SyoukaiForm) form;
int tokcd = syf.getTokcd();
Sql sql = new Sql();
List list = sql.SelectDate(tokcd);
request.setAttribute("List",list);
if(list.isEmpty())
{
target = "success";
}
else
{
target = "false";
}
return mapping.findForward( target );
}
}
其中target为false时跳转到Syoukai.jsp查询页面
————————————————————————————————
Syoukai.jsp:查询页面
<%@ page language="java" pageEncoding="UTF-8"
import="java.util.List,cn.form.SyoukaiVO,cn.sql.Sql"%>
<head>
<title>照会</title></head>
<%
SyoukaiVO svo = new SyoukaiVO();
int tokcd;
if (("").equals(request.getAttribute("LIST"))) {
List list = (List) request.getAttribute("LIST");
svo = (SyoukaiVO) list.get(0);
}
if (!"".equals(Integer.toString(svo.getTokcd()))) {
tokcd = svo.getTokcd();
}
%>
<html:html lang="true">
<body>
<html:form action="/syoukai" method="post">
<table width="1022" border="0" bgcolor="#CCCCCC">
<tr><% if("".equals(svo.getTokcd()) ||svo.getTokcd()==0){ %>
<td>得意先コード:
<input type="text" name="tokcd" /> </td><%
}else {%><td>得意先コード:
<input type="text" value=<%=svo.getTokcd()%> name="tokcd" /> </span></td><%} %>
<td width="335"></td>
</tr>
<tr><% if("".equals(svo.getName()) || svo.getName()== null){ %><td>得意先名: <input type="text" name="name" /></td><%
}else {%>
<td>得意先名 <input type="text" value=<%=svo.getName()%> name="name" /></td> <%} %>
<% if("".equals(svo.getTokrnk()) || null == svo.getTokrnk()){%>
<td>得意先ランク: <input type="text"
name="tokrnk" /></td>
<%}else{ %>
<td>得意先ランク<input type="text"
value=<%=svo.getTokrnk() %> name="tokrnk" /></td>
<%} %>
</tr>
</table>
<table>
<tr>
<td width="78" height="30"><input type="reset" value="取消" /></td>
<td width="132" height="30"><input type="submit" value="确认" /></td>
<td width="349" height="30"><input type="button" onclick="window.close()" value="终了" /></td>
</tr>
</table>
</html:form>
</body>
</html:html>
建表没问题,因为用这个写的其他的插入和删除操作都可以,查询牵扯到要输出到jsp页面,每次查询之后,结果都为空,估计是传值问题。在Action里面写了一条输出语句:
System.out.println("request"+request.getAttribute("List"));
显示结果是:request[cn.form.SyoukaiVO@11ee981]
是不是传值除了什么问题,jsp页面应该怎么写?
望高手指点,在这里先贴50分了,如果解决得好,追加
Sql:
public List SelectDate(int tokcd) throws ClassNotFoundException
{
ArrayList SelectList = new ArrayList();
String sql = "select * from tokumst where tokcd =";
sql = sql+ "'" + tokcd + "'";
System.out.println( "SQL is:" + sql );
Connection conn = null;
java.sql.ResultSet rs = null;
try
{
conn = getConnect();
Statement stmt=conn.createStatement();
rs = stmt.executeQuery(sql);
while(rs.next())
{
SyoukaiVO syo = new SyoukaiVO();
syo.setTokcd(rs.getInt("tokcd"));
syo.setName(rs.getString("name"));
SelectList.add(syo);
System.out.println("list add over!");
System.out.println(syo.getName());
System.out.println(rs.getString("name"));
System.out.println(rs.getString("kana"));
}
}
catch ( SQLException e )
{
e.printStackTrace();
}
finally
{
closeSql( conn );
}
// return SelectList.isEmpty()?null: SelectList;
return SelectList;
} 展开
SyoukaiForm和SyoukaiVO内容相同:
就是get,和set各个字段
————————————————————————————————
SyoukaiAction内容如下:
public class SyoukaiAction extends Action
{
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) throws Exception
{
String target = "false";
SyoukaiForm syf = (SyoukaiForm) form;
int tokcd = syf.getTokcd();
Sql sql = new Sql();
List list = sql.SelectDate(tokcd);
request.setAttribute("List",list);
if(list.isEmpty())
{
target = "success";
}
else
{
target = "false";
}
return mapping.findForward( target );
}
}
其中target为false时跳转到Syoukai.jsp查询页面
————————————————————————————————
Syoukai.jsp:查询页面
<%@ page language="java" pageEncoding="UTF-8"
import="java.util.List,cn.form.SyoukaiVO,cn.sql.Sql"%>
<head>
<title>照会</title></head>
<%
SyoukaiVO svo = new SyoukaiVO();
int tokcd;
if (("").equals(request.getAttribute("LIST"))) {
List list = (List) request.getAttribute("LIST");
svo = (SyoukaiVO) list.get(0);
}
if (!"".equals(Integer.toString(svo.getTokcd()))) {
tokcd = svo.getTokcd();
}
%>
<html:html lang="true">
<body>
<html:form action="/syoukai" method="post">
<table width="1022" border="0" bgcolor="#CCCCCC">
<tr><% if("".equals(svo.getTokcd()) ||svo.getTokcd()==0){ %>
<td>得意先コード:
<input type="text" name="tokcd" /> </td><%
}else {%><td>得意先コード:
<input type="text" value=<%=svo.getTokcd()%> name="tokcd" /> </span></td><%} %>
<td width="335"></td>
</tr>
<tr><% if("".equals(svo.getName()) || svo.getName()== null){ %><td>得意先名: <input type="text" name="name" /></td><%
}else {%>
<td>得意先名 <input type="text" value=<%=svo.getName()%> name="name" /></td> <%} %>
<% if("".equals(svo.getTokrnk()) || null == svo.getTokrnk()){%>
<td>得意先ランク: <input type="text"
name="tokrnk" /></td>
<%}else{ %>
<td>得意先ランク<input type="text"
value=<%=svo.getTokrnk() %> name="tokrnk" /></td>
<%} %>
</tr>
</table>
<table>
<tr>
<td width="78" height="30"><input type="reset" value="取消" /></td>
<td width="132" height="30"><input type="submit" value="确认" /></td>
<td width="349" height="30"><input type="button" onclick="window.close()" value="终了" /></td>
</tr>
</table>
</html:form>
</body>
</html:html>
建表没问题,因为用这个写的其他的插入和删除操作都可以,查询牵扯到要输出到jsp页面,每次查询之后,结果都为空,估计是传值问题。在Action里面写了一条输出语句:
System.out.println("request"+request.getAttribute("List"));
显示结果是:request[cn.form.SyoukaiVO@11ee981]
是不是传值除了什么问题,jsp页面应该怎么写?
望高手指点,在这里先贴50分了,如果解决得好,追加
Sql:
public List SelectDate(int tokcd) throws ClassNotFoundException
{
ArrayList SelectList = new ArrayList();
String sql = "select * from tokumst where tokcd =";
sql = sql+ "'" + tokcd + "'";
System.out.println( "SQL is:" + sql );
Connection conn = null;
java.sql.ResultSet rs = null;
try
{
conn = getConnect();
Statement stmt=conn.createStatement();
rs = stmt.executeQuery(sql);
while(rs.next())
{
SyoukaiVO syo = new SyoukaiVO();
syo.setTokcd(rs.getInt("tokcd"));
syo.setName(rs.getString("name"));
SelectList.add(syo);
System.out.println("list add over!");
System.out.println(syo.getName());
System.out.println(rs.getString("name"));
System.out.println(rs.getString("kana"));
}
}
catch ( SQLException e )
{
e.printStackTrace();
}
finally
{
closeSql( conn );
}
// return SelectList.isEmpty()?null: SelectList;
return SelectList;
} 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询