I have below a jps with below code with source and destination drop down and a button "Execute" which will call a servlet.
The servet will perform some operation based on the values selected.
JSP Code:
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<!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=ISO-8859-1">
<title/>
</head>
<form action="MySourceEnv" method="POST">
<select name="SourceEnv" >
<option>10.100.10.11</option>
<option>10.100.10.12</option>
</select>
</form>
<form action="MyDestEnv" method="POST">
<select name="DestEnv" >
<option>10.100.10.11</option>
<option>10.100.10.12</option>
</select>
</form>
<body>
<button onclick="location.href = 'http://localhost:7500/Project_1/JavaServlet';" id="RedirectButton" > Execute</button>
</body>
</html>
Servlet Code:
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class JavaServletClass extends HttpServlet {
public void init() throws ServletException {
}
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
String SourceEnvParam = request.getParameter("SourceEnv");
out.println("<h1>" + SourceEnvParam + "</h1>");
LogicMethod(SourceEnvParam);
}
private void LogicMethod(String SourceEnvParam) throws IOException {
// Some logic here
}
public void destroy() {
}
}
I'm getting the value of request.getParameter("SourceEnv") as Null when execute button is clicked and servlet is called.
What's wrong I'm doing here?