• Post Reply Bookmark Topic Watch Topic
  • New Topic

I can pass a value from a jsp to a class ?  RSS feed

 
arnaldo silveira
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,

I can pass a value from a jsp to a class without using servlet?

for example:

jsp



I need to send that value to a class I do not want to use servlet

anybody help?

thanks
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66144
146
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Two things:

  • Why are you still putting Java code in a JSP? That's a poor practice that has been dicredited for over 8 years now.


  • What is the relationship of the class to the JSP? The answer is most likely that this is something you should be taking care of prior to forwardning to the JSP from its controller.

  •  
    Vikas Aggarwal
    Ranch Hand
    Posts: 140
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    I agree with Bear Bibeault but if you really want to do it then call your class's method directly in JSP and pass as argument.
     
    arnaldo silveira
    Greenhorn
    Posts: 2
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    I understand it's not a good practice, but it takes a lot because I'm doing some studies. Do you have any examples? or ideas?
     
    Vikas Aggarwal
    Ranch Hand
    Posts: 140
    • Likes 1
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    <%@ page language="java" %>
    <%@ page import="com.mypackage.myclass" %>

    <%
    String testStr ="hello";

    myclass mc1= new myclass();
    myclass.myMethod(testStr );

    %>


     
    Bear Bibeault
    Author and ninkuma
    Marshal
    Posts: 66144
    146
    IntelliJ IDE Java jQuery Mac Mac OS X
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    arnaldo silveira wrote:I understand it's not a good practice, but it takes a lot because I'm doing some studies.

    I don't know what you mean by this. If are just learning JSP, it is in your own best interest to learn how to write JSPs using good practices and avoid building bad habits at the outset.
     
    Alex Hurtt
    Ranch Hand
    Posts: 98
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    arnaldo silveira wrote:hi,

    I can pass a value from a jsp to a class without using servlet?

    for example:

    jsp



    I need to send that value to a class I do not want to use servlet

    anybody help?

    thanks


    Not sure I understand why you are having a problem here...although using scriptlet code in JSP's is inadvisable, you can put any Java code you want to in a scriptlet. You have the whole java library at your disposal between those little <% and %> tags...you aren't limited to using only classes in the servlet/jsp API's or anything. Just instantiate an instance of the class whos method you want to call and pass the string to it...
     
    Stefan Evans
    Bartender
    Posts: 1836
    10
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Could it be as easy as:


    Instantiates a bean, and sets its property...
    Check out the jsp syntax reference for details.

     
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!