|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Noob: Includes and variables
In reading previous questions on this I am not understanding why my code isn't working.
I have editnews.jsp and within it I am including xt_editnews.jsp. In editnews I cannot call a variable that I defined in xt_editnews.jsp. Please help. Code follows: editnews.jsp <%@ page language = "java" import="java.sql.*, java.io.*, java.util.*, dbo.*" %> <%@ include file="../includes/top.jsp" %> <%@ include file="xt_editnews.jsp" %> <% out.print(vNewsTitle); %> <form action="news_action.jsp" method="post" name="editnews"> <input type="text" name="fnewstitle" value=""> </form> xt_editnews.jsp <%@ taglib prefix="c" uri="http://java.sun.com/jstl/core_rt" %> <%@ taglib prefix="sql" uri="http://java.sun.com/jstl/sql_rt" %> <jsp:useBean id="news" class="dbo.cnews" /> <% int vnewsid = Integer.parseInt(request.getParameter("newsid")); out.print(vnewsid); news.connect(); ResultSet rsSingleNews1 = news.getSingleNews(vnewsid); while (rsSingleNews1.next()) { String vNewsTitle = rsSingleNews1.getString("NewsTitle"); out.print(vNewsTitle); } %> If I do not do the out.print in editnews.jsp it works fine. When I do, I get: HTTP Status 500 - -------------------------------------------------------------------------------- type Exception report message description The server encountered an internal error () that prevented it from fulfilling this request. exception org.apache.jasper.JasperException: Unable to compile class for JSP An error occurred at line: -1 in the jsp file: null Generated servlet error: [javac] Since fork is true, ignoring compiler setting. [javac] Compiling 1 source file [javac] Since fork is true, ignoring compiler setting. [javac] C:\tomcat5\jakarta-tomcat-5\dist\temp\org\apache\jsp\manager\editnews_jsp.java:161: cannot resolve symbol [javac] symbol : variable vNewsTitle [javac] location: class org.apache.jsp.manager.editnews_jsp [javac] out.print(vNewsTitle); [javac] ^ [javac] 1 error |
|
#2
|
|||
|
|||
|
The reason that it cannot find the vNewsTitle variable is because you have decalred it local to the while loop and not the page.
Code:
while (rsSingleNews1.next())
{
String vNewsTitle = rsSingleNews1.getString("NewsTitle");
out.print(vNewsTitle);
}
Try this instead and see if it works. Code:
String vNewsTitle;
while (rsSingleNews1.next())
{
vNewsTitle = rsSingleNews1.getString("NewsTitle");
out.print(vNewsTitle);
}
|
|
#3
|
|||
|
|||
|
Hi Nemi,
Thank you!!! That was it exactly. --CC |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Java Help > Noob: Includes and variables |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|