【Servlet】根据用户输入的圆半径,输出圆面积

1、创建Servlet类

import java.io.*;
import javax.servlet.ServletException;
import javax.servlet.http.*;

public class CircleServlet extends HttpServlet{
	public void doGet(HttpServletRequest request, HttpServletResponse response) 
			throws ServletException,IOException{
		response.setContentType("text/html; charset=bg2312" );
		PrintWriter out = response.getWriter();
		double  r = Double.parseDouble(request.getParameter("r"));
		out.println(" 面积 = " + Math.PI*r*r);
		out.close();
	}
}


2、改写配置文件web.xml


		CircleServlet
		myDemo.CircleServlet
	
	
		CircleServlet
		/calcu
	

3、编写jsp调用servlet 

<%--clacu对应的是servlet的URL,调用CircleServlet --%> 圆的半径:



你可能感兴趣的:(JavaWeb)