这是我在viewAllNews.jsp里的部分代码:
<logic:iterate id="n" name="news">
<TR>
<TD><bean:write name="n" property="news_id"/></TD>
<TD><bean:write name="n" property="news_date"/></TD>
<TD><html:link page="/newsDetails.jsp" paramId="news_id" paramName="n" paramProperty="news_id"><bean:write name="n" property="news_title"/></html:link></TD>
</TR>
</logic:iterate>这是我在newsDetails.jsp里的部分代码:
String news_id = request.getParameter("news_id");
Connection con=DatabaseConn.getConnection();
Statement stmt=con.createStatement();
ResultSet rst=stmt.executeQuery("select * from news where news_id='news_id'");
while(rst.next())
{
out.println("<tr>");
out.println("<td>"+rst.getString("news_info")+"</td>");
out.println("</tr>");
}
rst.close();
stmt.close();
con.close();为什么我在运行时总是看不到newsDetails.jsp中想要的内容???哪里写错了?高手指点!
<logic:iterate id="n" name="news">
<TR>
<TD><bean:write name="n" property="news_id"/></TD>
<TD><bean:write name="n" property="news_date"/></TD>
<TD><html:link page="/newsDetails.jsp" paramId="news_id" paramName="n" paramProperty="news_id"><bean:write name="n" property="news_title"/></html:link></TD>
</TR>
</logic:iterate>这是我在newsDetails.jsp里的部分代码:
String news_id = request.getParameter("news_id");
Connection con=DatabaseConn.getConnection();
Statement stmt=con.createStatement();
ResultSet rst=stmt.executeQuery("select * from news where news_id='news_id'");
while(rst.next())
{
out.println("<tr>");
out.println("<td>"+rst.getString("news_info")+"</td>");
out.println("</tr>");
}
rst.close();
stmt.close();
con.close();为什么我在运行时总是看不到newsDetails.jsp中想要的内容???哪里写错了?高手指点!
应该是:("select * from news where news_id='"+news_id+"'");吧?
这样查询的是“news_id”,而不是news_id
改为
"select * from news where news_id='"+news_id+"'"
我用sql不是很多,没讲错吧。
news_id 是变量,不是字符串