main函数加载jetty,及java请求url
来源:互联网 发布:数据切片器 编辑:程序博客网 时间:2024/06/05 22:58
建立servlet处理请求protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub InputStream s=request.getInputStream(); String a=""; BufferedReader reader=new BufferedReader(new InputStreamReader(s)); String str; while ((str = reader.readLine()) != null){ System.out.println(str); a=str; } reader.close(); response.getWriter().write(a);}客户端代码public static void main(String[] args) throws IOException { // TODO Auto-generated method stub String host="http://localhost:8080/test/hello"; HttpURLConnection conn; try { URL url=new URL(host); conn = (HttpURLConnection)url.openConnection(); conn.setDoOutput(true); conn.setDoInput(true); conn.setRequestMethod("POST"); conn.setUseCaches(false); conn.setInstanceFollowRedirects(true); conn.setRequestProperty("Content-Type","application/x-www-form-urlencoded"); conn.connect(); DataOutputStream out = new DataOutputStream(conn.getOutputStream()); String hello=URLEncoder.encode("hello", "utf-8"); out.writeBytes(hello); out.flush(); out.close(); InputStream in=conn.getInputStream(); BufferedReader reader=new BufferedReader(new InputStreamReader(in)); String str; while ((str = reader.readLine()) != null){ System.out.println(str); } reader.close(); conn.disconnect(); } catch (MalformedURLException e) { // TODO Auto-generated catch block e.printStackTrace(); }}
加载jetty及webxml设置端口
public static void main(String[] args) {
// TODO Auto-generated method stub
Server server=new Server(8080);
WebAppContext context = new WebAppContext();
context.setDescriptor(“E:/work/test/src/main/webapp/WEB-INF/web.xml”);
context.setResourceBase(“E:/work/test/src/main/webapp”);
context.setContextPath(“/test”);
context.setParentLoaderPriority(true);
server.setHandler(context);
try {
server.start();
server.join();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
阅读全文
0 0
- main函数加载jetty,及java请求url
- java获取当前请求的url地址及各参数
- Java建立URL请求
- Java请求远程URL
- java URL请求
- Java建立URL请求
- Java建立URL请求
- java HTTP请求 URL
- JAVA代码url请求
- java代码请求URL
- java main 主函数
- java中的main函数
- JAVA中的main函数
- java的main函数
- JAVA main函数
- Java中的main函数
- Java main()函数
- JAVA中的main函数
- jsp网站访问次数统计的几种方法
- APP加固技术历程及未来级别方案:虚机源码保护
- Hudson 持续集成服务器的安装配置与使用
- 最优化问题综述
- 大型场景裁剪渲染
- main函数加载jetty,及java请求url
- JMS 使用
- Openresty最佳案例 | 第5篇:http和C_json模块
- oc runtime之weak
- reactjs router 4 (react-router-dom)使用嵌套路由遇到的问题
- gcc参数中的-I, -L和-l
- 图片文件操作工具类---ImageUtil
- Redis 在Centos7下配置开机自启动
- 关于正则匹配字符串之间的字符