项目所在路径,以及目录结构如下:
D:/code/java/temp/myproj/
- src/
- ColorSelect.java
- web/
- WEB-INF/
- web.xml
- index.jsp
index.jsp:
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html><body>
<p>My favorate color is: </p>
<form method="POST" action="ColorSelect.do">
<select name="color" size="1">
<option>red
<option>blue
<option>green
</select>
<input type="SUBMIT">
</form>
</body></html>
ColorSelect.java:
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
public class ColorSelect extends HttpServlet{
public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException{
response.setContentType("text/html");
PrintWriter out = response.getWriter();
String c = request.getParameter("color");
out.println("<br>color=" + c);
}
}
web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xm