#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2003
    Posts
    15
    Rep Power
    0

    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. #2
  3. No Profile Picture
    Clueless llama
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Feb 2001
    Location
    Lincoln, NE. USA
    Posts
    2,353
    Rep Power
    117
    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);
    }
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2003
    Posts
    15
    Rep Power
    0
    Hi Nemi,

    Thank you!!!

    That was it exactly.

    --CC

IMN logo majestic logo threadwatch logo seochat tools logo