Solved

jsp include page in .jsp file

Posted on 2010-08-31
12
1,404 Views
Last Modified: 2012-06-21
This code

In my .jsp page I am trying to include a file from the server. I had no problem in the html portion but can't get it to work inside the java portion. I have tried a variety of methods. Here's the code and the error is below.:

<%
        try
        {

                String to       = <%@ include  file="/email_domain.html" %> ;
                String bcc              ="";    

                String from    = email;
                String cc      = "me@here.com";
                String subject = "Subject - Contact Information";

                mail.SendMailBean sendMail=new mail.SendMailBean();

                String smtpSvr = "localhost.localdomain";
                String result  = sendMail.send(from,to,cc,bcc,subject,message,smtpSvr);
                //out.println("result *** "+result);
                count1=count1+1;

        }catch(Exception e)
        {      
                        out.println(e.getMessage());
        }      
               
}
else
{

//out.println("Else");
response.sendRedirect("contact_us.jsp");
}
}
catch(Exception e)
{
out.println("Error in redirect "+ e.getMessage());
}
//end to admin

%>



Heres the error
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

Generated servlet error:
Syntax error, insert "}" to complete ClassBody

An error occurred at line: 124 in the jsp file: /Emails/contact_mail.jsp
Generated servlet error:
Syntax error on tokens, delete these tokens

An error occurred at line: 124 in the jsp file: /Emails/contact_mail.jsp
Generated servlet error:
Syntax error, insert ";" to complete BlockStatements

Generated servlet error:
Syntax error, insert "Finally" to complete TryStatement

Generated servlet error:
Syntax error, insert "}" to complete Block

Generated servlet error:
Syntax error, insert "Finally" to complete TryStatement

Generated servlet error:
Syntax error, insert "}" to complete MethodBody


      org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:84)
      org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:328)
      org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:397)
      org.apache.jasper.compiler.Compiler.compile(Compiler.java:288)
      org.apache.jasper.compiler.Compiler.compile(Compiler.java:267)
      org.apache.jasper.compiler.Compiler.compile(Compiler.java:255)
      org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:556)
      org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:293)
      org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:291)
      org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

note The full stack trace of the root cause is available in the Apache Tomcat/5.5.9 logs.
0
Comment
Question by:richmarotta1
  • 4
  • 4
  • 3
  • +1
12 Comments
 

Expert Comment

by:AtulVerma
ID: 33570618
Hi,
You cannot use page directive inside a scriplet. Instead you can read it from a properties file or open a socket connection and read it into a variable. I'm not sure what you are trying to accomplish by doing this.
0
 
LVL 20

Expert Comment

by:Sathish David Kumar N
ID: 33570824
already ur string on page directive
then how can you use one more inside ?
0
 
LVL 20

Expert Comment

by:Sathish David Kumar N
ID: 33570833

String to       = <%@ include  file="/email_domain.html" %> ;





<%

        try

        {



                               String bcc              ="";    



                String from    = email;

                String cc      = "me@here.com";

                String subject = "Subject - Contact Information";



                mail.SendMailBean sendMail=new mail.SendMailBean();



                String smtpSvr = "localhost.localdomain";

                String result  = sendMail.send(from,to,cc,bcc,subject,message,smtpSvr);

                //out.println("result *** "+result);

                count1=count1+1;



        }catch(Exception e)

        {       

                        out.println(e.getMessage());

        }       

                

}

else

{



//out.println("Else");

response.sendRedirect("contact_us.jsp");

}

}

catch(Exception e)

{

out.println("Error in redirect "+ e.getMessage());

}

//end to admin



%>

Open in new window

0
 

Author Comment

by:richmarotta1
ID: 33570974
Didn't work. It could not resolve the variable "to". What would be the best way to read this variable from a properties file from within the scriplet?


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: 125 in the jsp file: /Emails/contact_mail.jsp
Generated servlet error:
to cannot be resolved


      org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:84)
      org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:328)
      org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:397)
      org.apache.jasper.compiler.Compiler.compile(Compiler.java:288)
      org.apache.jasper.compiler.Compiler.compile(Compiler.java:267)
      org.apache.jasper.compiler.Compiler.compile(Compiler.java:255)
      org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:556)
      org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:293)
      org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:291)
      org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
0
 
LVL 20

Expert Comment

by:Sathish David Kumar N
ID: 33571001
How the html  value set to string ??
String to       = <%@ include  file="/email_domain.html" %> ;  
 
0
 
LVL 20

Expert Comment

by:Sathish David Kumar N
ID: 33571013
write in property file and get it . or use rquest.getAttribute to get the value , change that as JSp
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 27

Expert Comment

by:mrcoffee365
ID: 33571477
dravidnsr - you are mistaken about how jsp pages are produced.

richmarotta1: AtulVerma gave you the right answer above.
0
 

Author Comment

by:richmarotta1
ID: 33571484
in HTML I use

<title><jsp:include page="/pagetitle.html" flush="true" /></title>
0
 
LVL 27

Expert Comment

by:mrcoffee365
ID: 33571554
Right -- that's the way you use jsp:include.  You can't use jsp:include as the value of a variable in a JSP file.
0
 

Author Comment

by:richmarotta1
ID: 33571597
mrcoffee,

We are taking over this site. This site was architected with a lot of redundant code. The code now needs to handle two different sites with distinct things like email domains. I am exchanging redundant code for includes so I can have 1 set of code for both sites.

What is the best way to read a properties file from within the jsp file?
0
 
LVL 27

Accepted Solution

by:
mrcoffee365 earned 500 total points
ID: 33571933
The most common way to have a properties file is to put the values in the webapp web.xml file.  For example:
 <context-param>
   <param-name>SomeProperty</param-name>
   <param-value>abcde</param-value>
 </context-param>

Then in the jsp page, get the value like this:
someProperty= application.getInitParameter("SomeProperty");

If appropriate, the contents of the context-param could be HTML and you could incorporate it into your JSP page.  You'll have to convert HTML < and > into < and > because < and > have special meanings in xml files.

You can also create a properties file, and read it from your webapp.  Then you would use Java File read and probably the Properties class for reading the properties out of the file.  It's easier to use web.xml, but it's not that bad using a special .properties file.
0
 
LVL 27

Expert Comment

by:mrcoffee365
ID: 33571947
Ah -- I wondered what the conversions on EE would do to that.  The greater than symbol has to be escaped into ampersand + gt + ;  in the web.xml file.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
simple jsp servlet and webservice web example 5 113
issue with pdf generation 2 85
String format issue 13 90
gZip compression filter 2 118
Scenario: Your operations manager has discovered an anomaly in your security system. The business will start to suffer within 15 minutes if it is a major IT incident. What should she do? We have 6 recommendations for managing major incidents (https:…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now