📄 searchpubs.java
字号:
package com.fc.web;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.fc.bo.PubsBo;
import com.fc.dao.Pubs;
import com.fc.dao.tools.BoException;
public class SearchPubs extends HttpServlet {
/**
* Constructor of the object.
*/
public SearchPubs() {
super();
}
/**
* Destruction of the servlet. <br>
*/
public void destroy() {
super.destroy(); // Just puts "destroy" string in log
// Put your code here
}
/**
* 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 {
this.doPost(request, response);
}
/**
* 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 {
Pubs pubs = new Pubs();
pubs.setType(Integer.parseInt(request.getParameter("type")));
pubs.setQuyu(request.getParameter("quyu"));
pubs.setHuxing(request.getParameter("huxing"));
pubs.setWuyeleixing(request.getParameter("wuyeleixing"));
pubs.setXiaoqu(request.getParameter("xiaoqu"));
PubsBo bo = new PubsBo();
List<Pubs> list = null;
if (pubs.getHuxing().equals("0")) {
if (pubs.getWuyeleixing().equals("0")) {
if (pubs.getXiaoqu() == "") {
try {
list = bo.findByQuyu(pubs);
//System.out.println("1");
} catch (BoException e) {
e.printStackTrace();
}
} else {
try {
list = bo.findByXiaoQu_Quyu(pubs);
//System.out.println("2");
} catch (BoException e) {
e.printStackTrace();
}
}
} else {
if (pubs.getXiaoqu() == "") {
try {
list = bo.findByWuyeleixing_Quyu(pubs);
//System.out.println("3");
} catch (BoException e) {
e.printStackTrace();
}
} else {
try {
list = bo.findByXiaoQu_Quyu_Wuyeleixing(pubs);
//System.out.println("4");
} catch (BoException e) {
e.printStackTrace();
}
}
}
} else {
if (pubs.getWuyeleixing().equals("0")) {
if (pubs.getXiaoqu() == "") {
try {
//System.out.println("5");
list = bo.findByHuxing_Quyu(pubs);
} catch (BoException e) {
e.printStackTrace();
}
} else {
try {
//System.out.println("6");
list = bo.findByXiaoQu_Quyu_Huxing(pubs);
} catch (BoException e) {
e.printStackTrace();
}
}
} else {
if (pubs.getXiaoqu() == "") {
try {
list = bo.findByQuyu_Huxing_Wuyeleixing(pubs);
//System.out.println("7");
} catch (BoException e) {
e.printStackTrace();
}
} else {
try {
list = bo.findByXiaoQu_Quyu_Huxing_Wuyeleixing(pubs);
//System.out.println("8");
} catch (BoException e) {
e.printStackTrace();
}
}
}
}
PrintWriter out = response.getWriter();
response.setCharacterEncoding("utf8");
response.setContentType("text/html;charset=utf-8");
if (list != null) {
for (int i = 0; i < list.size(); i++) {
out.print("标题:"+list.get(i).getTitle() + "<br>");
out.print("地址:"+list.get(i).getAddr() + "<br>");
out.print("户型:"+list.get(i).getHuxing() + "<br>");
out.print("价格:"+list.get(i).getJiaoyijiage() + "<br>");
out.print("发布时间:"+list.get(i).getPubsTime() + "<br>");
out.print("描述:"+ list.get(i).getMiaoshu() + "<br>");
out.print("<hr>");
}
}else{
response.sendRedirect(request.getContextPath()+"/user/erro.jsp?msg=not find");
}
}
/**
* Initialization of the servlet. <br>
*
* @throws ServletException
* if an error occure
*/
public void init() throws ServletException {
// Put your code here
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -