I'm developing simple web application. I've created Dynamic Web Project in Eclipse Mars and I'm using Java 1.8 and Tomcat v8.0.36. I've created a simple form:
<!DOCTYPE html>
<html>
<head>
<title>Coffee Advice Page</title>
</head>
<body>
<form action=”SelectCoffee.do”>
Select Coffee characteristics<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>
<input type="submit" value="Submit">
</form>
</body>
</html>
A Servlet:
package com.example.web;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@SuppressWarnings("serial")
public class CoffeeSelectionServlet extends HttpServlet {
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
System.out.println("Inside doGet()");
PrintWriter printWriter = response.getWriter();
printWriter.println("doGet() is working fine!");
}
}
Web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
id="WebApp_ID" version="3.1">
<display-name>CoffeeAdvice</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<!-- <welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file> -->
</welcome-file-list>
<servlet>
<servlet-name>Servlet1</servlet-name>
<servlet-class>com.example.web.CoffeeSelectionServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Servlet1</servlet-name>
<url-pattern>/SelectCoffee.do</url-pattern>
</servlet-mapping>
</web-app>
But when I start Tomcat server and submit this form, I get 404 Error with query string: http://localhost:8080/CoffeeAdvice/%C3%A2%E2%82%AC%C2%9DSelectCoffee.do%C3%A2%E2%82%AC%C2%9D?%E2%80%9Dcolor%E2%80%9D=%E2%80%9Dlight%E2%80%9D
which is not I intended. If I make GET request directly from browser bar:
http://localhost:8080/CoffeeAdvice/SelectCoffee.do?color=light
It works absolutely fine!
Please let me know why this query string is generated distorted like this and what I'd have to change.
Any help would be much appreciated!