richmarotta1
asked on
jsp include page in .jsp file
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,b cc,subject ,message,s mtpSvr);
//out.println("result *** "+result);
count1=count1+1;
}catch(Exception e)
{
out.println(e.getMessage() );
}
}
else
{
//out.println("Else");
response.sendRedirect("con tact_us.js p");
}
}
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.JasperEx ception: 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 .DefaultEr rorHandler .javacErro r(DefaultE rrorHandle r.java:84)
org.apache.jasper.compiler .ErrorDisp atcher.jav acError(Er rorDispatc her.java:3 28)
org.apache.jasper.compiler .JDTCompil er.generat eClass(JDT Compiler.j ava:397)
org.apache.jasper.compiler .Compiler. compile(Co mpiler.jav a:288)
org.apache.jasper.compiler .Compiler. compile(Co mpiler.jav a:267)
org.apache.jasper.compiler .Compiler. compile(Co mpiler.jav a:255)
org.apache.jasper.JspCompi lationCont ext.compil e(JspCompi lationCont ext.java:5 56)
org.apache.jasper.servlet. JspServlet Wrapper.se rvice(JspS ervletWrap per.java:2 93)
org.apache.jasper.servlet. JspServlet .serviceJs pFile(JspS ervlet.jav a:291)
org.apache.jasper.servlet. JspServlet .service(J spServlet. java:241)
javax.servlet.http.HttpSer vlet.servi ce(HttpSer vlet.java: 802)
note The full stack trace of the root cause is available in the Apache Tomcat/5.5.9 logs.
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,b
//out.println("result *** "+result);
count1=count1+1;
}catch(Exception e)
{
out.println(e.getMessage()
}
}
else
{
//out.println("Else");
response.sendRedirect("con
}
}
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.JasperEx
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
org.apache.jasper.compiler
org.apache.jasper.compiler
org.apache.jasper.compiler
org.apache.jasper.compiler
org.apache.jasper.compiler
org.apache.jasper.JspCompi
org.apache.jasper.servlet.
org.apache.jasper.servlet.
org.apache.jasper.servlet.
javax.servlet.http.HttpSer
note The full stack trace of the root cause is available in the Apache Tomcat/5.5.9 logs.
already ur string on page directive
then how can you use one more inside ?
then how can you use one more inside ?
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
%>
ASKER
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.JasperEx ception: 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 .DefaultEr rorHandler .javacErro r(DefaultE rrorHandle r.java:84)
org.apache.jasper.compiler .ErrorDisp atcher.jav acError(Er rorDispatc her.java:3 28)
org.apache.jasper.compiler .JDTCompil er.generat eClass(JDT Compiler.j ava:397)
org.apache.jasper.compiler .Compiler. compile(Co mpiler.jav a:288)
org.apache.jasper.compiler .Compiler. compile(Co mpiler.jav a:267)
org.apache.jasper.compiler .Compiler. compile(Co mpiler.jav a:255)
org.apache.jasper.JspCompi lationCont ext.compil e(JspCompi lationCont ext.java:5 56)
org.apache.jasper.servlet. JspServlet Wrapper.se rvice(JspS ervletWrap per.java:2 93)
org.apache.jasper.servlet. JspServlet .serviceJs pFile(JspS ervlet.jav a:291)
org.apache.jasper.servlet. JspServlet .service(J spServlet. java:241)
javax.servlet.http.HttpSer vlet.servi ce(HttpSer vlet.java: 802)
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperEx
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
org.apache.jasper.compiler
org.apache.jasper.compiler
org.apache.jasper.compiler
org.apache.jasper.compiler
org.apache.jasper.compiler
org.apache.jasper.JspCompi
org.apache.jasper.servlet.
org.apache.jasper.servlet.
org.apache.jasper.servlet.
javax.servlet.http.HttpSer
How the html value set to string ??
String to = <%@ include file="/email_domain.html" %> ;
String to = <%@ include file="/email_domain.html" %> ;
write in property file and get it . or use rquest.getAttribute to get the value , change that as JSp
dravidnsr - you are mistaken about how jsp pages are produced.
richmarotta1: AtulVerma gave you the right answer above.
richmarotta1: AtulVerma gave you the right answer above.
ASKER
in HTML I use
<title><jsp:include page="/pagetitle.html" flush="true" /></title>
<title><jsp:include page="/pagetitle.html" flush="true" /></title>
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.
ASKER
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?
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?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.
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.