• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Make hyperlink that when clicked call a java method and display results

 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi I'm using servlet to search for learning concepts. for example when the user query about validation and click submit the results appear as following:

important learning resources:
[url]hyperlink1:
hyperlink2:[/url]
:

other related topics
[url]topic1
topic2
topic3[/url]

for the first list it is dirct hyperlink. For the second list I need to hyperlink each topic so that when clicked the topic will be send to a method to search for it and display result. So there is no direct URL but I need to allow the user (if want to) to select one of the topic and send it for a search methd. How this can be done? shall I use the <a> tag with herf? but there is no url. or is there another way to make the action go to another servelet or method?

Thanks
 
Ranch Hand
Posts: 1514
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can associate an action with each hyperlink, then in your servlet check the action and call the appropriate method.
 
Nada Bajnaid
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
what is the right way to do this. is this code correct

printWriter out = response.getWriter();
out.println ("<a herf=pakageName\className\methodName" + topic1+ "</a>");

Thanks
 
Sheriff
Posts: 67746
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
There is no such attribute as herf. And you need to make sure that whatever HTML you are emitting is correct.

Why are you using a servlet to create the view? That's the job of the JSP.
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You seem to think it's possible to make a hyperlink which will connect to your server and call an arbitrary method in your Java code. It isn't.

When connecting to a servlet, the link will either call the doGet() method or the doPost() method of the servlet depending on how the link is set up.

So if you need certain methods to be called, the way to do that is to pass parameters to the servlet, which the servlet code will then inspect and do the appropriate thing, as Bosun Bello already suggested.
 
Nada Bajnaid
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm not sure that I clearly understand what you said. This is my first servelet that manipulates OWL ontology using Jena and JessBridge. Everything works fine except this part. Do you mean that I build another servlet within the project that accepts parameters and call it in hyperlink?

the herf is the an attribute of the <a> tag that allow displaying text as hyperlink in html. Is there another way?

Thanks
 
Nada Bajnaid
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't think this can be done using JSP as the output is changrd each time based on creating instances of other classes and calling some methods of these classes which returns the results in vectors that are displayed to the user
 
Bear Bibeault
Sheriff
Posts: 67746
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

Nada Bajnaid wrote:the herf is the an attribute of the <a> tag that allow displaying text as hyperlink in html.


No, its not. Check your spelling.

And of course it can be done in a JSP. JSP is all about dynamic displays.
 
Nada Bajnaid
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry it is href
 
Nada Bajnaid
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK. suppose that I make this search task using JSP then it displays the results as in first message then when one of the topics is clicked the same process will be done for this topic as the query text. Will it be possible to receive client request (clicking the topic) in a JSP and then make the JSP call itself to restart the search process?

Is there a good reference for such code that I can learn from it. I run out of time

Thanks
 
Nada Bajnaid
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for your support

I did it using the onClick attribute

out.println ("<a href=\"newPage.html\" onClick=\"SQA.System/testMethod(s);return false\">" +(String)itr.next()+"</a><br>");

where testMethod placed in the same servlet. and SQA>System is the package.

There is no syntax error. The application runs correctly untill I click on one of the topics where the function testMethod should be processed but it doesn't. I think the problem is with the function URL. I also tried it without the package name.

Does any one knows what I did wrong? How I should pass the method testMethod?

Thanks
 
Can you smell this for me? I think this tiny ad smells like blueberry pie!
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic