0

因此,我再次陷入困境,这是我的 .JSP 页面代码,我在其中尝试单击艺术家姓名,它将显示他们出现的电影。我在第一个查询中一切正常,但是当我到达在 queryMovies 中,我尝试将电影的标题链接回电影 ID,这应该带我到另一个页面,我得到错误 mid cannot be resolve to a variable。我究竟做错了什么?谢谢。

    <html>
<head>
<%@ include file="header.htm" %>
<%@ page import="java.sql.*" %>
<%
    Class.forName("com.mysql.jdbc.Driver").newInstance();
    String cs="jdbc:mysql://localhost:3306/hunters?user=root&password=password";
    Connection cxn = DriverManager.getConnection(cs);
    Statement stm = cxn.createStatement();

int oscar = 0;

String fname = request.getParameter("fname");
String lname = "", dob = "", nation = "", imdb = "", url = "", newaid = "", title = "", studio = "", role = "", rlsdate = "";
String queryArtist = "SELECT * FROM artist WHERE aid = '" + request.getParameter("selectedName") + "';";

ResultSet rsArtist = stm.executeQuery(queryArtist);

    rsArtist.next();
    fname = rsArtist.getString("fname"); 
    lname = rsArtist.getString("lname");
    dob = rsArtist.getString("dob").substring(0,4);
    nation = rsArtist.getString("nation");
    imdb = rsArtist.getString("imdb");
    url = rsArtist.getString("url");
%>
    <title><%= fname %> <%= lname %></title>

<h2><FONT COLOR="B22222"><%= fname%> <%= lname%></FONT></h2>

<p>Born in: <%= dob%></p> 
<p>Nationality: <%= nation%></p>
<p>IMDB Bio: <a href="http://www.imdb.com/name/<%= imdb%>/"  target="_blank">http://www.imdb.com/name/<%= imdb%>/</a></p>
<%
if (url == null)
{
out.println("<br />");
}
else 
{
out.println("Website: <a href=" + url + "target=_blank>" + url + "</a><br>");
}
%>
<hr />
<h3><FONT COLOR="B22222">Filmography</FONT></h3>
<%
newaid = request.getParameter("selectedName");



String queryMovies = "SELECT * FROM artist, movies, artistmovie WHERE artistmovie.mid = movies.mid AND artist.aid = artistmovie.aid AND artist.aid = '"; 
    queryMovies += request.getParameter("selectedName") + "';";

ResultSet rsMovies = stm.executeQuery(queryMovies);

while(rsMovies.next())
{
    title = rsMovies.getString("title");
    studio = rsMovies.getString("studio");
    rlsdate = rsMovies.getString("rlsdate");
    role = rsMovies.getString("role");
    oscar = rsMovies.getInt("oscar");
    mid = rsMovies.getInt("mid");

    out.println("<tr><td>&nbsp;</td><td><a href= artistmovie.jsp?SelectedTitle=" + mid + ">" + title + " <a/></td>");
    out.println("<td>&nbsp;&nbsp;&nbsp;</td><td>(" + studio + "</a></td>"); 
    out.println("<td></td><td>" + rlsdate + ")</td>");  
    out.println("<td>&nbsp;&nbsp;</td><td>" + role + "</td></br></br>");

}
if (oscar == 0)
{
    out.println("<td>&nbsp;</td><td><br /></td>");
}
else
{
    out.println("<td>&nbsp;</td><td>Won oscar</td></tr>");
}
%>
<%@ include file="footer.htm" %>
</body>
</html>
4

1 回答 1

0

改变

out.println("<tr><td>&nbsp;</td><td><a href= artistmovie.jsp?SelectedTitle=" + mid + ">" + title + " <a/></td>");

out.println("<tr><td>&nbsp;</td><td><a href=\"artistmovie.jsp?SelectedTitle="+ mid +"\">" + title + " <a/></td>");

应该管用。

除了这个

out.println("<td>&nbsp;&nbsp;&nbsp;</td><td>(" + studio + "</a></td>"); 

你在哪里开始“ <a>”标签,它在“”附近结束<td>

于 2012-04-17T16:27:50.470 回答