• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Calling function with onClick attribute

 
Nada Bajnaid
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • 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
 
Abhishek Purwar
Ranch Hand
Posts: 63
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • 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
  • 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 Java Spring
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
  • 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
 
Akshay D Joshi
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • 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.....
 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic