Forums Register Login

FIRST EXAMPLE NOT WORKING..!!

+Pie Number of slices to send: Send
I have made the web.xml file and the form.html file.But I am not able to open up the html form from the browser using http://localhost:8080/Beer-v1/form.html.

My folders are as follows

HTML FILE ----> C:\Program Files\Java\apache-tomcat-7.0.6\webapps\Beer-v1\form.html
WEB-INF FILE ----> C:\Program Files\Java\apache-tomcat-7.0.6\webapps\Beer-v1\WEB-INF

When I directly click on the html file is it working but when I start the tomcat and then open http://localhost:8080/Beer-v1/form.html address, it is showing an error message "The requested resource (/Beer-v1/form.html) is not available."

Were exactly is the error ??
+Pie Number of slices to send: Send
where is your web.xml? and what is in it?

Regards,
Frits
+Pie Number of slices to send: Send
thanks Fritz for replying to my query but I have managed to correct it.
I was using a wrong directory for deployment..

I have a new query now.

I have the form.html page up and running.But when I select the color and hit 'Submit' on the page,it gives me a error message HTTP Status 405 -"HTTP method GET is not supported by this URL"

Html file

<html><body>
<h1 align="center">Shri Ram Beer Selection Page <h1/>
<form methd="POST"
action="SelectBeer.do">
Select beer characterstics<p>
Color:
<select name="color" size="1">
<option value="light"> light </option>
<option value="amber"> amber </option>
<option value="brown"> brown </option>
<option value="dark"> dark </option>
</select>
<br><br>
<center>
<input type="SUBMIT">
</center>
</form></body></html>
--------------------------------------------------------------------------------------------------------

SelectBeer.java file

package com.example.web;

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;

public class BeerSelect extends HttpServlet {
public void doPost(HttpServletRequest request,HttpServletResponse response) throws IOException,ServletException {
response.setContentType("text/html");
PrintWriter out=response.getWriter();
out.println("Beer Selection Advice<br>");
String c=request.getParameter("color");
out.println("<br>Got beer color "+c);
}
}
---------------------------------------------------------------------------------------------------------------

xml file

<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
version="2.4">

<servlet>
<servlet-name>Ch3 Beer</servlet-name>
<servlet-class>com.example.web.BeerSelect</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>Ch3 Beer</servlet-name>
<url-pattern>/SelectBeer.do</url-pattern>
</servlet-mapping>

</web-app>
---------------------------------------------------------------------------------------------------------------


I hope you can help me on this one too.


Thanking you
Shagun
+Pie Number of slices to send: Send
as you have misspelled the method in:

<form methd="POST" action="SelectBeer.do">


It sends a GET to the server and in your Servlet it looks for the method doGet(), which you haven't implemented.

Change it to method="POST" and it should work.

Regards,
Frits
+Pie Number of slices to send: Send
Thank you so much. It is working..!!
Thanks a lot

Regards
Shagun
For my next trick, I'll need the help of a tiny ad ...
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 1109 times.
Similar Threads
Help -unable to run servlet in APACHE
HFS: Problem with deploying and testing Beer-v1 App
Problems with the Example from HF Servlets & JSP in Chapter 3
Tomcat Problem
Tomcat WebApp Deployment
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 02:58:03.