• 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
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

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

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 67753
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
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.

  •  
    Ranch Hand
    Posts: 140
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • 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
      Number of slices to send:
      Optional 'thank-you' note:
    • 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
      Number of slices to send:
      Optional 'thank-you' note:
    • 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
    Sheriff
    Posts: 67753
    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

    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.
     
    Ranch Hand
    Posts: 98
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • 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...
     
    Bartender
    Posts: 1845
    10
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • 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.

     
    I do some of my very best work in water. Like this tiny ad:
    Smokeless wood heat with a rocket mass heater
    https://woodheat.net
    reply
      Bookmark Topic Watch Topic
    • New Topic