• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

jsp include file problem

 
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i wrote a code to dynamically generate a page :



but got errors :













i have 1 big doubt , can jsp include action be used in a conditional statement .. because there where i got all errors .

looking forward for answer
 
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

i have 1 big doubt , can jsp include action be used in a conditional statement .. because there where i got all errors .



The JSP standard action can take part in conditional statements, loops etc. The include directive however, cannot. So your approach is okay.
Try to reference the file using the path from the web application root (start the path with /).
 
Ranch Hand
Posts: 2908
1
Spring Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Look carefully, is it JSP tag is allowed inside scriptlet enclosed Java code ?
 
Sebastian Janisch
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Sagar Rohankar wrote:
Look carefully, is it JSP tag is allowed inside scriptlet enclosed Java code ?



Yes it is ... that's totally fine. You can mix HTML, Tags (as long as these are not SimpleTags), and scriptlets freely.
 
Sheriff
Posts: 67745
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Sebastian Janisch wrote:Yes it is ... that's totally fine.


Hogwash. You can't embed JSP actions inside scriptlets.
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Sebastian Janisch wrote:Yes it is ... that's totally fine. You can mix HTML, Tags (as long as these are not SimpleTags), and scriptlets freely.


No you can't:Not legal, the same thing for custom tags. Text between scriptlet tags must be Java.
 
Sebastian Janisch
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry, I didn't see that the scriptlet is not closed. That's what I meant when I said it's okay to mix them.

tushar panda, your code should look like this..


However, it is bad practice to put Java in JSP. Try to avoid that.
 
tushar panda
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
sorry for late reply .

yeah now got it right , i missed out the (click!=null) condition .

but why shall i need it when i know "click" will never be null , because either of the three values(tenth,twelth,engg) will be submitted . (i need a bit explanation here)

--TUSHAR
 
Sebastian Janisch
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The problem wasn't the null check but rather the problem that you did not close and reopen your scriptlet tags and hence your JSP standard action is embedded in a scriptlet which is illegal .
 
tushar panda
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Sebastian Janisch wrote:The problem wasn't the null check but rather the problem that you did not close and reopen your scriptlet tags and hence your JSP standard action is embedded in a scriptlet which is illegal .



No no , once again i remove the (check!=null) condition and closed the scriplet tags (which i didn't before) but it gave error ,
it means the condition is needed here , but again , why shall , the click is nebver going to be null .

please clarify me because if i remove the check!=null it gives error ..a bit confused and exicited ..
 
Bear Bibeault
Sheriff
Posts: 67745
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please show the new code, with code tags. Making us guess what your code looks like is not going to get you far.
 
Sebastian Janisch
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The check for null is not mandatory and it should not raise any exceptions if you omit the check...

What exception is thrown ?
 
tushar panda
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bear Bibeault wrote:Please show the new code, with code tags. Making us guess what your code looks like is not going to get you far.



here is the new one :



and the error :

org.apache.jasper.JasperException: An exception occurred processing JSP page /form-data/test.jsp at line 3

1: <HTML>
2: <% String click = request.getParameter("click"); %>
3: <% if(click.trim().equals("tenth")) { %>
4: <jsp:include page="data/tenth.jsp" />
5: <% } %>
6:


Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:505)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:416)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

root cause

java.lang.NullPointerException
org.apache.jsp.form_002ddata.test_jsp._jspService(test_jsp.java:57)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

note The full stack trace of the root cause is available in the Apache Tomcat/6.0.20 logs.
 
Sebastian Janisch
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, that means that 'click' is null.

Please put code between the code tags.
 
tushar panda
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
and this give no error :

 
Sebastian Janisch
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Check my post above.
 
tushar panda
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Sebastian Janisch wrote:Well, that means that 'click' is null.

Please put code between the code tags.




oops you are right , the first time i run the code click=null ,, ,, sorry for asking a dumb question ..
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic