📄 showchargeservlet.java
字号:
package unicom.action;
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;
import unicom.factory.ServiceFactory;
import unicom.service.IChargeService;
import unicom.service.IMobileService;
/**
* @author xiaogang
* 日期:Apr 18, 2008
* 功能:更据charge.jsp页面动态选择列表框,动态从数据库中取出内容,并显示到页面上
* 优点:
* 缺点:
* 建议:认真学习JavaScript脚本技术和ajax技术,将桌面系统的异步优势运用到Web应用上
*/
public class ShowChargeServlet extends HttpServlet {
/**
* The doGet method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to get.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
//防止中文乱码
request.setCharacterEncoding("UTF-8");
response.setContentType("text/html;charset=UTF-8");
//获取客户端的输出流
PrintWriter out = response.getWriter();
//获取请求数据
String code = request.getParameter("code");
IChargeService mobileService = ServiceFactory.createChargeService();
double price = mobileService.getChargePriceByCode(code);
//向客户端打印数据,另一方面在浏览器端利用xmlHttpRequest.responseText接收该数据
out.println(price);
}
/**
* The doPost method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to post.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doGet(request,response);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -