[Logo]
Forums Register Login
jsp include file problem
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
 

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 /).

Look carefully, is it JSP tag is allowed inside scriptlet enclosed Java code ?
 

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.
 

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


Hogwash. You can't embed JSP actions inside scriptlets.
 

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.
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.
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
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 .
 

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 ..
Please show the new code, with code tags. Making us guess what your code looks like is not going to get you far.
The check for null is not mandatory and it should not raise any exceptions if you omit the check...

What exception is thrown ?
 

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.
Well, that means that 'click' is null.

Please put code between the code tags.
and this give no error :

Check my post above.
 

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 ..
Wink, wink, nudge, nudge, say no more ... https://richsoil.com/cards


This thread has been viewed 6387 times.

All times above are in ranch (not your local) time.
The current ranch time is
Jun 18, 2018 19:12:15.