?? 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("南京市場當(dāng)前豬肉價格:"+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);
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -