Win a copy of Rust Web Development this week in the Other Languages forum!
  • 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:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

Calling function with onClick attribute

 
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 trying to call a function testMethod using onClick



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 Topic1 where the function testMethod should be processed but it doesn't. I think the problem is with the way I passed the function I also tried it without the package name.

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

Thanks
 
Ranch Hand
Posts: 63
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You cannot call servlet methods directly from html page. onClick attribute works for javascript functions and not for servlet methods.
For servlet methods, you need to create url mapping and call url for servlet from HTML page.
 
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. can I call another servlet using onClick? if not

What is url mapping? and how I can do it?

in my application the user enter a query concept and when submit it, in the doPost method where an ontology model is accessed and the results are displayed as following

important learning resources
hyperlink1...
hyperlink2...
:

Related Topics
Topic1
Topic2
:

I have no problem with the first list. With the second list I need each topic to be a link that when clicked the same process will be repeated where the query now is the selected topic? it works except for that part where the links are not direct URLs instead the process of the doPost is repeated but this time the user will not enter the query instead the query is assigned to the selected topic

This is why I tried methods to do the search jop and display the results.

Any suggestion is appreciated
 
Abhishek Purwar
Ranch Hand
Posts: 63
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Url mapping is the path which is associated with servlet if you want to access servlet using http request.
In web.xml file, one can define url mapping for different servlets.

Can you provide sample urls which you want to invoke from different links??
 
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 use tomcat 7 where web.xml is not required instead I use @WebServlet("/SQA") wher in my html file I use
<form action="SQA" method = "get">

in the doGet method I use the following to get the user query
response.getWriter().print("<form action = './SQA' method = 'post'>");

then in the doPost model I do the search process which creates the results then from these results I need to do the process again? shall I call the doPost again asigning value to the query variable instead of getting it from parameters?
 
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 the doPost method I do the following

ReadOntology model = new ReadOntology();
String queryStr = request.getParameter("query");
model.coreLearningObjects(queryStr);
:

can I call the doPost method from the doPost itself passing value to the queryStr?

something like this

out.println ("<a href=\ "http://localhost:8080/myProjectName/myServletName?queryStr=" + selectedTopic+"</a>");

 
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
Or shall I create another servlet and call its doPost passing parameters to it (?queryStr=)
if yes what is the way to do it?

Thanks
 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Nada Bajnaid

I think...
You should write java script function .....
call this function on click of link.......
And in java script function assign the form's action to your servlet....

It will be called automatically.....
 
reply
    Bookmark Topic Watch Topic
  • New Topic