aspose file tools*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes FIRST EXAMPLE NOT WORKING..!! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "FIRST EXAMPLE NOT WORKING..!!" Watch "FIRST EXAMPLE NOT WORKING..!!" New topic
Author

FIRST EXAMPLE NOT WORKING..!!

Shagun Bhardwaj
Greenhorn

Joined: Feb 15, 2011
Posts: 17
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 ??
Frits Walraven
Creator of Enthuware JWS+ V6
Bartender

Joined: Apr 07, 2010
Posts: 1696
    
  25

where is your web.xml? and what is in it?

Regards,
Frits
Shagun Bhardwaj
Greenhorn

Joined: Feb 15, 2011
Posts: 17
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
Frits Walraven
Creator of Enthuware JWS+ V6
Bartender

Joined: Apr 07, 2010
Posts: 1696
    
  25

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
Shagun Bhardwaj
Greenhorn

Joined: Feb 15, 2011
Posts: 17
Thank you so much. It is working..!!
Thanks a lot

Regards
Shagun
 
Don't get me started about those stupid light bulbs.
 
subject: FIRST EXAMPLE NOT WORKING..!!