H5调用servlet
来源:互联网 发布:整型数据的输出格式 编辑:程序博客网 时间:2024/06/05 22:49
在H5里面写好程序接口,这儿使用的是Hbuilder软件
在index文件里面写如下代码
<!DOCTYPE html><html><head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" /> <title></title> <script src="js/mui.min.js"></script> <link href="css/mui.min.css" rel="stylesheet"/></head><body><script>mui.plusReady(function(){ mui.ajax('http://10.5.15.10:8080/test/servlet/test',{data:{category:'news'},dataType:'json',//服务器返回json格式数据type:'post',//HTTP请求类型 ......success:function(data){alert(data.result);}});});</script></body></html>
在web.xml
<?xml version="1.0" encoding="UTF-8"?><web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> <display-name></display-name> <servlet> <description>This is the description of my J2EE component</description> <display-name>This is the display name of my J2EE component</display-name> <servlet-name>test</servlet-name> <servlet-class>com.test.test</servlet-class> </servlet> <servlet-mapping> <servlet-name>test</servlet-name> <url-pattern>/servlet/test</url-pattern> </servlet-mapping> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list></web-app>
在java中写好
package com.test;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;public class test extends HttpServlet {/** * Constructor of the object. */public test() {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 {//response.setContentType("text/html");PrintWriter out = response.getWriter();out.println("{\"result\":\"sucess\"}");out.flush();out.close();}/** * Initialization of the servlet. <br> * * @throws ServletException if an error occurs */public void init() throws ServletException {// Put your code here}}
0 0
- H5调用servlet
- H5调用摄像头
- H5调用本地摄像头
- H5 调用摄像头
- H5调用本地app
- h5调用手机照相机
- H5 调用摄像头
- H5调用本地app
- 原生H5调用摄像头
- H5调用js代码
- H5调用摄像头
- 调用 Servlet
- servlet调用
- Servlet 调用servlet
- Dcloud H5+ API调用实例
- H5调用原生百度地图
- H5调用手机振动实现
- H5调用手机振动实现
- 浅析μC/OS-II OSTimeDly()函数和OSTimeTick()函数工作原理
- Jquery点击切换文本框是否可用
- 【第五节】Java代码实现栈----【链表的存储形式】
- ssis+ssas+ssrs 介绍
- 九大排序算法-C语言实现及详解
- H5调用servlet
- 封装一个类搞定90%安卓客户端与服务器端交互
- Spring+SpringMVC+Mybatis整合系列(一)Maven安装与配置
- maven 依赖调解 依赖冲突 排除
- 关于JVM常用的GC算法
- JAVA从入门到精通读书笔记 第一章
- 常用的一些URI
- GitHub上整理的一些常用工具
- [小米对话框]WindowManager.LayoutParams.TYPE_SYSTEM_ALERT对话框不显示?