ActionForm中的html怎么被实体化了(无可用分) 代码给全点啊,只写一句哪知道你是怎么调用的title呀。起码也得把form给出来呀 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 我没有用title是这样的在ActionFormBean中有一个超链接的标签< a href ='...'>...</a>然后返回到jsp页面就是这样一个过程! actionFormBeanpackage question;import org.apache.struts.action.*;import javax.servlet.http.*;import javax.sql.DataSource;import java.sql.*;import javax.servlet.ServletContext;import java.util.*;import javax.naming.*;public class indexAction extends Action { public ActionForward execute(ActionMapping actionMapping, ActionForm actionForm, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) { DataSource dataSource = null; Connection conn = null; Statement stmt = null; ResultSet rs = null; String sql = null; ArrayList table = null; indexActionForm row = null; //分页变量 String url = "indexAction.do"; String queryString = ""; int page = 0; int pageSize = 5; String batchShowUrl = ""; int tmpi = 0; String title = ""; int id; sql = "select * from question"; DB db = new DB(); db.getConnect(); //rs = db.query(sql); try { page = Integer.parseInt(httpServletRequest.getParameter("page")); } catch(NumberFormatException e){ page = 1; } rs = db.batchShow(sql, pageSize, page, url, queryString); batchShowUrl = db.getBatchShowUrl(); table = new ArrayList(); try { while (!rs.isAfterLast() && tmpi < pageSize) { tmpi++; row = new indexActionForm(); //row.setTitle(rs.getString("title")); title = rs.getString("title"); id = rs.getInt("id"); title = new String(title.getBytes("ISO8859-1")); title = "<a href='view.do?id=" + id + "' target='_blank'>" + title + "</a>"; row.setTitle(title); row.setNickname(rs.getString("nickname")); row.setAddtime(rs.getString("addtime")); rs.next(); table.add(row); } } catch (Exception e) { System.out.println("rs.next error:" + e); } finally { try { rs.close(); db.close(); } catch (Exception e) {} } httpServletRequest.setAttribute("batchShowUrl", batchShowUrl); httpServletRequest.setAttribute("table", table); return actionMapping.findForward("index"); }} jsp<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %><%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %><%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %><%@ page contentType="text/html; charset=GBK" %><html><head><title>首页</title></head><body bgcolor="#c0c0c0"><div align="center" style="font-size:16pt"> <b>Struts数据库入门实例--简单答疑系统</b></div><div align="center"><html:form action="/indexAction"> <table border="0" cellpadding="1" cellspacing="1" bgcolor="#000000" align="center" width="600"> <tr bgcolor="#CCCCCC"> <td colspan="3" align="right"><%=request.getAttribute("batchShowUrl")%></td> </tr> </tr> <tr bgcolor="#CCCCCC"> <td width="358" align="center"><b>Question</b></td> <td width="97"><b>Nickname</b></td> <td align="center" width="135"><b>Addtime</b></td> </tr> <!--列出数据--> <logic:notEmpty name="table"> <logic:iterate id="row" name="table" scope="request"> <tr bgcolor="#CCCCCC"> <td width="358"><bean:write name="row" property="title"/></td> <td width="97"><bean:write name="row" property="nickname"/></td> <td align="center" width="135"><bean:write name="row" property="addtime"/></td> </tr> </logic:iterate> </logic:notEmpty> <tr bgcolor="#CCCCCC"> <td colspan="3" align="right"><%=request.getAttribute("batchShowUrl")%></td> </tr> </table> <html:link href="addQuestion.jsp" >Add Question</html:link> </html:form> </div></body></html> http://www.javayou.com/showlog.jspe?log_id=166#836 <%@ page contentType="text/html; charset=GBK" %>改为<%@ page contentType="text/html; charset=gb2312" %>试试吧,有时struts会把代码变成二进制的代码,我也部太清楚 多线程 UDP 程序 谁能教教咱git到底怎么用啊,要疯了 怎么读取网页来的数据 mysql inert 问题 Please help--Missing IN or OUT parameter at index:: 1 分页:多条件查询时,查询条件放到什么地方?url?form?session? 一个关于数字签证的问题~~~~~~在线啊~~~ 菜鸟求一段学习代码 关于处理Exception的问题 web开发中,常用ID到Name转化的问题 servlet放在哪里? 为什么我用不了自己写的JavaBean?
就是这样一个过程!
import javax.servlet.http.*;
import javax.sql.DataSource;
import java.sql.*;
import javax.servlet.ServletContext;
import java.util.*;
import javax.naming.*;public class indexAction
extends Action {
public ActionForward execute(ActionMapping actionMapping,
ActionForm actionForm,
HttpServletRequest httpServletRequest,
HttpServletResponse httpServletResponse) { DataSource dataSource = null;
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
String sql = null;
ArrayList table = null;
indexActionForm row = null;
//分页变量
String url = "indexAction.do";
String queryString = "";
int page = 0;
int pageSize = 5;
String batchShowUrl = "";
int tmpi = 0; String title = "";
int id; sql = "select * from question";
DB db = new DB();
db.getConnect();
//rs = db.query(sql);
try {
page = Integer.parseInt(httpServletRequest.getParameter("page"));
}
catch(NumberFormatException e){
page = 1;
}
rs = db.batchShow(sql, pageSize, page, url, queryString);
batchShowUrl = db.getBatchShowUrl(); table = new ArrayList();
try {
while (!rs.isAfterLast() && tmpi < pageSize) {
tmpi++;
row = new indexActionForm();
//row.setTitle(rs.getString("title"));
title = rs.getString("title");
id = rs.getInt("id");
title = new String(title.getBytes("ISO8859-1"));
title = "<a href='view.do?id=" + id + "' target='_blank'>" + title + "</a>";
row.setTitle(title);
row.setNickname(rs.getString("nickname"));
row.setAddtime(rs.getString("addtime"));
rs.next();
table.add(row);
}
}
catch (Exception e) {
System.out.println("rs.next error:" + e);
}
finally {
try {
rs.close();
db.close();
}
catch (Exception e) {}
}
httpServletRequest.setAttribute("batchShowUrl", batchShowUrl);
httpServletRequest.setAttribute("table", table);
return actionMapping.findForward("index");
}
}
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ page contentType="text/html; charset=GBK" %>
<html>
<head>
<title>首页</title>
</head>
<body bgcolor="#c0c0c0">
<div align="center" style="font-size:16pt"> <b>Struts数据库入门实例--简单答疑系统</b></div>
<div align="center"><html:form action="/indexAction">
<table border="0" cellpadding="1" cellspacing="1" bgcolor="#000000" align="center" width="600">
<tr bgcolor="#CCCCCC">
<td colspan="3" align="right"><%=request.getAttribute("batchShowUrl")%></td>
</tr>
</tr>
<tr bgcolor="#CCCCCC">
<td width="358" align="center"><b>Question</b></td>
<td width="97"><b>Nickname</b></td>
<td align="center" width="135"><b>Addtime</b></td>
</tr>
<!--列出数据-->
<logic:notEmpty name="table">
<logic:iterate id="row" name="table" scope="request">
<tr bgcolor="#CCCCCC">
<td width="358"><bean:write name="row" property="title"/></td>
<td width="97"><bean:write name="row" property="nickname"/></td>
<td align="center" width="135"><bean:write name="row" property="addtime"/></td>
</tr>
</logic:iterate>
</logic:notEmpty>
<tr bgcolor="#CCCCCC">
<td colspan="3" align="right"><%=request.getAttribute("batchShowUrl")%></td>
</tr>
</table>
<html:link href="addQuestion.jsp" >Add Question</html:link> </html:form> </div>
</body>
</html>
改为
<%@ page contentType="text/html; charset=gb2312" %>
试试吧,有时struts会把代码变成二进制的代码,我也部太清楚