⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 googleservlet.java

📁 JSP2.0实用教程实例源码
💻 JAVA
字号:
package myGoogle;     import java.io.IOException;  import java.io.PrintWriter;     import javax.servlet.*;import javax.servlet.http.*;public class GoogleServlet extends HttpServlet {      	public void doGet(HttpServletRequest request, HttpServletResponse response)    	throws ServletException, java.io.IOException {		doGet(request, response);     } //end doGet	 	public void doPost(HttpServletRequest request, HttpServletResponse response)    	throws ServletException,java.io.IOException{	   	    //支持中文输入的内容	    request.setCharacterEncoding("GB2312");		String query = request.getParameter("query");		String restrict = request.getParameter("restrict");				boolean isValid = (query == null || query.length() < 1) ? false : true;			//set the MIME type of the response, "text/html"	    response.setContentType("text/html");		//支持中文输出内容        response.setCharacterEncoding("GB2312");	    //use a PrintWriter send text data to the client who has requested the servlet	    java.io.PrintWriter out = response.getWriter();				//Begin assembling the HTML content	    out.println("<html><head>");	    out.println("<title>查询结果</title></head><body>");				if (! isValid){		    out.println("<h2>查询关键字不能为空</h2>");		} else {		    //使用JavaBean处理查询			GoogleBean gb = new GoogleBean();		    gb.setFilter(true);		    //设置分行的HTML标记 			gb.setLineSep("<br/>");						if (restrict != null && restrict.length() > 0)			    gb.setRestrict(restrict);						    gb.setQuery(query);		    //输出查询结果到返回页面			out.println("<h2>查询结果如下:</h2>");		    try {		    	out.println( gb.getSearchResults());			} catch (Exception e){				    throw new ServletException( e.getMessage() );			}		}		out.println("</body></html>");	    out.close();	}// doPost}//HttpServlet

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -