• Post Reply Bookmark Topic Watch Topic
  • New Topic

Importing a java file into jsp

 
Varnam Aayiram
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi folks..

I need to access in a jsp file, the value held by a string variable in a servlet . I imported the servlet into the jsp file this way:



I than created an instance of the servlet in the jsp file this way:



I than tried to access the string variable 'FK_idfacility' of the servlet this way:



I get a 'not a statement, ; expected' when I didnt use a ';' and 'not a statement' when I use one. How should I access the value held by the FK_idfacility variable than?

 
Devaka Cooray
Marshal
Posts: 5168
485
Chrome Eclipse IDE Google App Engine IntelliJ IDE jQuery Postgres Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Using Java codes inside a JSP is a bad practice. Creating an object of a Servlet class is worst than that. What you should do is, direct the request to the servlet, add the value of that variable to a proper scope using setAttribute method, and then dispatch the request to the the JSP. Within the JSP, you can access that attribute using EL, or standard tags.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65524
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Devaka speaks wisely. You should not ever be trying to use a Servlet for something other than it is intended, and certainly never create instances of them yourself. And Java code in a JSP is a practice that has been discredited for over 8 years now. Time to catch up!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!