• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

How do I make a button that will ahref to the servlet for action ?  RSS feed

 
Ranch Hand
Posts: 433
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi expert,

I am stuck at creating a button which will ahref to servlet

Please find attached the buttons look and feel.

Here's what I have :





I believe button onclick is for javascript or more frequently used in asp.net app but this is JSP and I just don't know how to make it work. :(

Hope someone can help me out on this.

Tks!


MainPage.jpg
[Thumbnail for MainPage.jpg]
 
Marshal
Posts: 67164
169
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A JSP is just a template to create the page on the server to send to the client. By the time the page gets to the browser, it is just an HTML page like any other. In other words, you would code the activity the same way in a JSP that you would any other page.

Please read this article to understand how JSP works.
 
tangara goh
Ranch Hand
Posts: 433
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Bear Bibeault wrote:A JSP is just a template to create the page on the server to send to the client. By the time the page gets to the browser, it is just an HTML page like any other. In other words, you would code the activity the same way in a JSP that you would any other page.

Please read this article to understand how JSP works.



I have tried the following but not sure why it is not working :



EMSONCRUD is referring to the contextPath

and list all is at the WebServlet

so I want to get the jsp to perform the Search...and the functions logic all there at the preformSearch...


Not sure why last time it works but now it is not working....:(

Hope someone can help ....Tks.
 
Bear Bibeault
Marshal
Posts: 67164
169
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

tangara goh wrote:
I have tried the following but not sure why it is not working :


How is it not working? Just saying "it doesn't work" isn't useful.


Do you have a servlet mapping to match?

And, you shouldn't include the "http://localjost:8013" in the URL. Leave the host off when creating a URL into the same web app.

And, you shouldn't hard-code the context path. See the JspFaq for how to get this programmatically.

so I want to get the jsp to perform the Search


No you don't. A JSP should never perform any processing. Do that in the controllers (or lower delegates).
 
tangara goh
Ranch Hand
Posts: 433
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Bear Bibeault wrote:

tangara goh wrote:
I have tried the following but not sure why it is not working :


How is it not working? Just saying "it doesn't work" isn't useful.


Do you have a servlet mapping to match?

And, you shouldn't include the "http://localjost:8013" in the URL. Leave the host off when creating a URL into the same web app.

And, you shouldn't hard-code the context path. See the JspFaq for how to get this programmatically.

so I want to get the jsp to perform the Search


No you don't. A JSP should never perform any processing. Do that in the controllers (or lower delegates).



This is my latest attempt and listAll appear in my servlet like this ;



And here's the jsp


I want to make it such that when the user click on Enquire 'button' it will go to the index which is the Servlet pathInfo where it lies all the logic to forward to another jsp page or go back to the Main Page.

When I entered a record into the enquire which is found, it is suppose to bring me to another page.

The error I am getting is 404 and the browser just show http://localhost:8013/index, it seems that it is taking in the index as a jsp page....

I have also tried various ways like <a > etc but it will just give me a 404 not found or another one is 405 methods not allowed.......

Please help. Tk.s
 
Bear Bibeault
Marshal
Posts: 67164
169
IntelliJ IDE Java jQuery Mac Mac OS X
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your form action does not match your servlet mapping. And it is unnatural for the parameters to be part of the path, for form=based APIs. Why are heading in that direction?

And, you shouldn't be hard-codeine the contact path. Obtain it programmatically. See JspFaq for details.
 
tangara goh
Ranch Hand
Posts: 433
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Bear Bibeault wrote:Your form action does not match your servlet mapping. And it is unnatural for the parameters to be part of the path, for form=based APIs. Why are heading in that direction?

And, you shouldn't be hard-codeine the contact path. Obtain it programmatically. See JspFaq for details.



Yes.  You are right.  It took me awhile to know that the context path has to be left out....it was so long ago that I did my servlet stuff....

Not sure if outside world is still using it....
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!