• Post Reply Bookmark Topic Watch Topic
  • New Topic

how to use the expression language when object is not built in a servlet?

 
Edmund Castermund
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
have searched around for this and can't believe I don't know the answer...

currently an app I'm working on has an index.jsp file that needs some dynamic content. Since that does not hit a servlet first, I am using the jsp:useBean property and using scriptlets, which I know is not the best practice.

How do you create an obj when you are not building in a servlet, adding as an attribute to the request, and then forwarding to the jsp?
Thanks!
 
Edmund Castermund
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok, stupid, should have just tested. I am using this:



then just using regular EL type markup in the jsp:



is that the right way?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65530
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Edmund Castermund wrote:currently an app I'm working on has an index.jsp file that needs some dynamic content. Since that does not hit a servlet first, I am using the jsp:useBean property and using scriptlets, which I know is not the best practice.

As you know this is not a good practice, why not fix this instead of working around the problem?
 
Edmund Castermund
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry...did not frame question well.

The old version of the index page had the useBean and scriptlets. I still have the useBean, but have used the EL syntax to output its values on the jsp page.

As for the useBean issue...in the case of a jsp page, such as an index.jsp that does not have an object that is constructed and then dispatched to the jsp by a servlet...what is the best way to create on object when you need dynamic content?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65530
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Edmund Castermund wrote:As for the useBean issue...in the case of a jsp page, such as an index.jsp that does not have an object that is constructed and then dispatched to the jsp by a servlet

Again, this is the problem I would fix. No JSP should be directly accessed without a servlet controller.

...what is the best way to create on object when you need dynamic content?

If you insist on just band-aiding the problem rather than fixing it, then I'd use a combination of useBean and <c:set>. The setProperty tag is outdated.
 
Edmund Castermund
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sorry, should have searched more. I can associate the index.jsp with the welcome file list in web.xml, correct?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65530
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Or better, the servlet that serves as its page controller. That way all JSPs, including "index" (or whatever your first page view is) can reside in WEB-INF, protected from direct viewing, and be treated the same way.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!