?? c110servlet.java
字號:
package com.house.project.S1.M11.C110;
/**
* <p>Title: DisposeServlet.java
* <p>Description: 菜單系統配置
* <p>Copyright: Copyright (c) 2006
* <p>Company: Yangxh
* @author Wufz
* @version v1.0
* @see com.yangxh.project.fundamental.wdxx.WangdianServlet
*********************************************************************************************
* Date * Developers ID * Modlog * Description *
*********************************************************************************************
03/07/2006 Wufz V1.0
*/
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.jasper.runtime.JspRuntimeLibrary;
//import com.house.project.S1.M11.C110.C110Dao;
import com.house.project.exception.SQLException;
import com.house.project.exception.UnAuthorizedException;
import com.house.project.servlet.BusinessServlet;
import com.house.util.DataTransfer;
import com.house.util.PageControl;
import com.house.project.S1.C1Bean;
public class C110Servlet extends BusinessServlet {
private String path = "/jsp/S1/M11/C110/";
/* 處理post請求 */
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException {
response.setContentType("text/html;charset=GBK");
try {
String functionMthodName = checkPost(request, response); // 用戶請求驗證,若成功返回請求功能方法名
search(request, response);
} else if (functionMthodName.equalsIgnoreCase("ADD")) {
add(request, response);
} else if (functionMthodName.equalsIgnoreCase("MODIFY")) {
modify(request, response);
} else if (functionMthodName.equalsIgnoreCase("DELETE")) {
delete(request, response);
}
else if (functionMthodName.equalsIgnoreCase("DETAIL")) {
detail(request, response);
}
// else if (functionMthodName.equalsIgnoreCase("PRINT")) {
// print(request, response);
// }
} catch (UnAuthorizedException ue) // 用戶權限驗證失敗
{
handlerException(request, response, ue.getMessage());
} catch (SQLException e) // 數據庫操作失敗
{
handlerException(request, response, e);
}
}
/* 處理Get請求 */
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException {
String functionID = request.getParameter("functionID");
String selectedValue = request.getParameter("selectedValue");
int id = -1;
if (selectedValue != null && !selectedValue.trim().equals("")){
id = Integer.parseInt(selectedValue);
}
try {
if (functionID !=null && !functionID.trim().equals("") ){
print(request, response,id);
}
else{
search(request, response);
}
}
catch (SQLException e) // 數據庫操作失敗
{
handlerException(request, response, e);
}
}
// 處理網點信息查詢功能
private void search(HttpServletRequest request, HttpServletResponse response)
throws ServletException, SQLException, IOException {
String parm1;
String parm2;
parm1 = request.getParameter("parm1");
if(parm1 == null)
request.setAttribute("parm1", "");
else
request.setAttribute("parm1", parm1);
parm2 = request.getParameter("parm2");
if(parm2 == null)
request.setAttribute("parm2", "");
else
request.setAttribute("parm2", parm2);
int curpage ;
String reSearchFlag = request.getParameter("ReSearch");
if(reSearchFlag != null) //重新查詢, jumpPage應該設為1
{
curpage = 1;
}
else
{
String jumpPage = request.getParameter("jumpPage") ;
if(jumpPage == null)
{
curpage = 1 ;
}
else
{
curpage = Integer.parseInt(jumpPage) ;
}
}
if(parm1==null || parm1.equals(""))
{
parm1 = null;
}
else
{
parm1 = DataTransfer.toDBString(parm1);
}
if(parm2==null || parm2.equals(""))
{
parm2 = null;
}
else
{
parm2 = DataTransfer.toDBString(parm2);
}
C110Dao dao = new C110Dao();
PageControl pageCtl = dao.searchParaByName(parm1, parm2, curpage);
request.setAttribute("pageCtl", pageCtl);
this.getServletContext().getRequestDispatcher(path +"index.jsp").forward(request , response);
return;
}
private void add(HttpServletRequest request, HttpServletResponse response)
throws ServletException, SQLException, IOException {
String status = request.getParameter("status"); // 用該狀態來標識是進入增加頁面還是增加后保存動作
if (status == null) // 進入增加初始頁面
{
this.getServletContext().getRequestDispatcher(
path + "add.jsp").forward(request, response);
return;
}
else
{
C1Bean bean = new C1Bean();
JspRuntimeLibrary.introspect(bean, request);
C110Dao dao = new C110Dao();
dao.insertItem(bean);
search(request, response);
}
}
private void modify(HttpServletRequest request, HttpServletResponse response)
throws ServletException, SQLException, IOException {
String status = request.getParameter("status");
if (status == null)
{
int id = Integer.parseInt(request.getParameter("selectedValue"));
C110Dao dao = new C110Dao();
C1Bean bean = dao.getItem(id);
request.setAttribute("bean", bean);
this.getServletContext().getRequestDispatcher(path + "modify.jsp")
.forward(request, response);
}
else
{
C1Bean bean = new C1Bean();
JspRuntimeLibrary.introspect(bean, request);
C110Dao dao = new C110Dao();
try
{
dao.updateItem(bean);
}
catch (SQLException e)
{
handlerException(request, response, e.getMessage());
return;
}
search(request, response);
}
}
private void delete(HttpServletRequest request, HttpServletResponse response)
throws ServletException, SQLException, IOException {
String[] allNo = request.getParameterValues("selectedValue");
C110Dao dao = new C110Dao();
dao.removeItems(allNo);
search(request, response);
return;
}
private void detail(HttpServletRequest request, HttpServletResponse response)
throws ServletException, SQLException, IOException {
int id = Integer.parseInt(request.getParameter("selectedValue"));
C110Dao dao = new C110Dao();
C1Bean bean = dao.getItem(id);
request.setAttribute("bean", bean);
this.getServletContext().getRequestDispatcher(path + "detail.jsp")
.forward(request, response);
return;
}
private void print(HttpServletRequest request, HttpServletResponse response, int id)
throws ServletException, SQLException, IOException {
//int id = Integer.parseInt(request.getParameter("selectedValue"));
C110Dao dao = new C110Dao();
C1Bean bean = dao.getItem(id);
request.setAttribute("bean", bean);
this.getServletContext().getRequestDispatcher(path + "print.jsp")
.forward(request, response);
return;
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -