• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Servlet Newbie

 
Jeff S
Greenhorn
Posts: 2
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm writing my first servlet and I am having a problem. I am using JRun with IIS. I am trying to call a servlet from an html form. What do I put in the action command of the form? <form method="post" action=[some one help me here]>. Also, how is the servlet compiled? How is the .class file generated? Basically, how do I compile the servlet? Thanks
 
SoonAnn Lim
Ranch Hand
Posts: 155
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<form method="post" action="....">, you must supply the target of this html, i.e., by taking action on this form element, the associated servlet will handle the request from this form. Servlet is just a java class file with diferent construct. Compile your servlet as regular java source file. You need to know Java before diving into servlet, otherwise you will have many difficulties in the future in this field.
 
Jeff S
Greenhorn
Posts: 2
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a directory called /project-db and a context path of the same name. In the top level directory, my html form exists. In a subdirectory, I have web-inf/classes file, where my servlet resides. So my html form is located in /project-db and my servlet is located in /project-db/web-in/classes/MyServlet.
Knowing this, what goes into the action attribute of the form element within the html form? That is <form method="post" action=[WHAT GOES HERE?]>.
Thanks
 
Carl Trusiak
Sheriff
Posts: 3340
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JavaRanch has a Naming Policy In order to be entered in the drawing for the book giveaway, your name must meet this policy. Please reregister with a correct name.
Try
action="/project-db/servlet/MyServlet"
That will work with any servlet 2.2 compliant server.
------------------
Hope This Helps
Carl Trusiak, SCJP2
 
Wirianto Djunaidi
Ranch Hand
Posts: 210
Ruby Ubuntu VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jeff,
It would be:

-Ryo
 
Subbu Aswathanarayan
Ranch Hand
Posts: 73
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your "action" thing should look like this
action=http://<YourServerName>/<YourApplicationName>/servlet/<ServeletName(without .class extention)
<YourServerName> : name of ur server(eg www.abc.com)
<YourApplicationName> : The name of your webapplication if you have created one.this maynot be the same as your directory name which in your case is /project-db.Try to remember what name did u give to your application while setting up the JMC.you can find it out by logging in to JMC again.
Since you have put the servlet in /classes directory you have to use /servlet.JRun automatically translates /servlet to /web-inf/classes.
go thro the JRun documentation.Its very useful.
Subbu
Originally posted by Jeff S:
I have a directory called /project-db and a context path of the same name. In the top level directory, my html form exists. In a subdirectory, I have web-inf/classes file, where my servlet resides. So my html form is located in /project-db and my servlet is located in /project-db/web-in/classes/MyServlet.
Knowing this, what goes into the action attribute of the form element within the html form? That is <form method="post" action=[WHAT GOES HERE?]>.
Thanks

 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic