响应客户端请求(servlet与jsp)
2015-07-17 15:25
579 查看
同时处理客户端的get请求和post请求:
Servlet:
web.xml配置:
访问:http://localhost:8080/server/market?type=5
JSP: test.jsp
访问:
http://localhost:8080/server/test.jsp?type=5 返回type=5 OK
Servlet:
public class getAndPost extends HttpServlet { @Override public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException , IOException { response.setContentType("text/html"); //获取参数 request.getParameter("type"); //获取字符输出流,返回参数值 PrintWriter writer = response.getWriter(); writer.print(ret); writer.flush(); } @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { //doGet调用doPost,实现Get请求 doPost(req, resp); } }
web.xml配置:
<servlet> <servlet-name>market</servlet-name> <servlet-class>com.test.MarketService</servlet-class> </servlet> <servlet-mapping> <servlet-name>market</servlet-name> <url-pattern>/market</url-pattern> </servlet-mapping>
访问:http://localhost:8080/server/market?type=5
JSP: test.jsp
<% String type = request.getParameter("type"); out.println("type=="+type); out.println("OK"); %>
访问:
http://localhost:8080/server/test.jsp?type=5 返回type=5 OK
相关文章推荐
- javascript父子页面通讯实例详解
- javascript操作DOM元素
- js获取select标签选中的值
- JavaScript定时机制setTimeout与setInterval研究
- javaScript Element对象
- javascript实现的闭包简单实例
- javascript实现的字符串与十六进制表示字符串相互转换方法
- JS刷新的时候遇到浏览器刷新提示框的问题
- 【翻译】如何创建Ext JS暗黑主题之一
- JavaScript全部勾选所有复选框
- javaScript DOM编程
- 【翻译】如何创建Ext JS暗黑主题之一
- 【翻译】如何创建Ext JS暗黑主题之一
- 【翻译】如何创建Ext JS暗黑主题之一
- AJAX 跨域请求的解决办法:使用 JSONP获取JSON数据
- 再谈javascript面向对象编程
- Javascript 面向对象编程
- js 框架都有哪几种(转载)
- 理解 JS 回调函数中的 this
- JavaScript实现基于十进制的四舍五入实例