I have a very basic Java EE project, consisting of one servlet Main.java and one
associated jsp file (their contents are below).
The problem I'm encountering is that, when in debugging mode I fill the fields in the form and
press the "Submit" button, I can see that the request.getParameterNames is empty, when it
should contain "left", "right", etc.
Any help appreciated.
Contents of Main.java file :
package com.miniCalculatrice.servlets;
import java.io.IOException;
import java.util.Enumeration;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* Servlet implementation class Main
*/
@WebServlet("/Main")
public class Main extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public Main() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
this.getServletContext().getRequestDispatcher
("/WEB-INF/main.jsp").
forward(request, response);
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
Enumeration<String> enu=request.getParameterNames();
boolean see=enu.hasMoreElements();
for (; enu.hasMoreElements();) {
String elt=enu.nextElement();
System.out.println(elt);
}
doGet(request, response);
}
}
Contents of main.jsp file :
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Calculatrice</title>
</head>
<body>
<p>
</p>
<form method="post" action="main" enctype="multipart/form-data">
<input type="text" name="left" id="left" />
<select multiple>
<option value="plus">+</option>
<option value="minus">-</option>
<option value="times">x</option>
<option value="divided">/</option>
</select>
<input type="text" name="right" id="right" />
<input type="submit" value="Calculer"/>
</form>
</body>
</html>
Also, the web.xml file of my project is as follows :
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:jsp="http://java.sun.com/xml/ns/javaee/jsp" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0">
<servlet>
<servlet-name>Main</servlet-name>
<servlet-class>com.miniCalculatrice.servlets.Main</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Main</servlet-name>
<url-pattern>/main</url-pattern>
</servlet-mapping>
</web-app>