📄 showpriceservlet.java
字号:
/*
* Created on 2004-6-13
*
* To change the template for this generated file go to
* Window - Preferences - Java - Code Generation - Code and Comments
*/
package com.servlet;
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;
/**
* @author haoyulong
*
* To change the template for this generated type comment go to
* Window - Preferences - Java - Code Generation - Code and Comments
*/
public class ShowPriceServlet extends HttpServlet {
protected void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
//TODO Method stub generated by Lomboz
response.setContentType("text/html;charset=gb2312");
PrintWriter out = response.getWriter();
String Price=(String)getServletConfig().getServletContext().getAttribute("Price");
if(Price==null){Price=new String("0");
}
String oldPrice=(String)request.getSession().getAttribute("OldPrice");
out.println("<HTML><HEAD><TITLE>南京猪肉价格显示 "
+ "</TITLE></HEAD>");
out.println("<BODY>");
out.println("南京市场当前猪肉价格:"+Price+"元/斤");
if(oldPrice!=null){
out.println("<BR>");
out.println("南京市场过去猪肉价格:"+oldPrice+"元/斤");
int p1=Integer.parseInt(oldPrice,10);
int p2=Integer.parseInt(Price,10);
if(p1<p2)out.println(" 唉~~,猪肉又涨价了,日子没法过了!");
if(p1>p2)out.println(" 好消息,猪肉降价了!");
}
out.println("</BODY></HTML>");
//更新会话中的猪肉价格
request.getSession().setAttribute("OldPrice",Price);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -