当前位置: 首页 > news >正文

自建站推广网络公司运营是干啥的

自建站推广,网络公司运营是干啥的,外贸电商网站制作,wordpress主题屏蔽更新一、前言 本课程的难度较高#xff0c;需要将Servlet原理和IO课程全部学完。 二、当前项目使用方式 (1).自定义servlet 自定义servlet需要实现WebServlet并且实现name和urlMapping 重启进行访问 http://localhost:8090/myServlet (2).自定义html 重启进行访问 http://loc…一、前言 本课程的难度较高需要将Servlet原理和IO课程全部学完。 二、当前项目使用方式 (1).自定义servlet 自定义servlet需要实现WebServlet并且实现name和urlMapping 重启进行访问 http://localhost:8090/myServlet (2).自定义html 重启进行访问 http://localhost:8090/index.html (3).关于servlet位置 在SearchClassUtil类当中可以设置servlet包的位置 三、关于web须知 我们本次设计的tomcat能够将用户请求的资源进行返回 资源分类 1.静态资源:所有用户访问后得到的结果都是一样的称为静态资源。静态资源可以直接被浏览器解析。*例如html/css/jpg/js.. 2.动态资源每个用户访问相同的资源后得到的结果可能不一样称为动态资源。动态资源被访问后需要先转化为静态资源再返回给浏览器浏览器进行解析*例如servlet/jsp ...四、tomcat设计原理 五、实现tomcat对静态资源的访问 (1).创建maven项目 (2).tomcat启动阶段 配置HttpServlet 创建HttpServletRequest接口 public interface HttpServletRequest {public String getUrl();public void setUrl(String url);public String getMethod();public void setMethod(String method); }创建HttpServletResponse接口 public interface HttpServletResponse {void write(String context) throws IOException; }创建HttpServlet /*** class HttpServlet*/ public abstract class HttpServlet {public abstract void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException;public abstract void doPost(HttpServletRequest request,HttpServletResponse response);/*** HttpServlet 实现service方法*/public void service(HttpServletRequest request,HttpServletResponse response) throws IOException {if(GET.equals(request.getMethod())){doGet(request,response);}else if(POST.equals(request.getMethod())){doPost(request,response);}}}创建工具类描述返回的信息 /*** 返回信息工具类*/ public class ResponseUtil {public static final String responseHeader200 HTTP/1.1 200 \r\nContent-Type:text/html \r\n\r\n;public static String getResponseHeader404(){return HTTP/1.1 404 \r\nContent-Type:text/html \r\n\r\n 404;}public static String getResponseHeader200(String context){return HTTP/1.1 200 \r\nContent-Type:text/html \r\n\r\n context;} }配置注解信息 Retention(RetentionPolicy.RUNTIME) //注解的生命周期运行期间保留 Target(value {ElementType.TYPE,ElementType.FIELD}) // 该注解作用在类上边 public interface WebServlet {String urlMapping() default ; //自定义的servlet路径 }配置servlet容器 创建ServletConfig存储注解信息 /*** 注解上的信息*/ public class ServletConfig {private String urlMapping; //2.urlprivate String classpath; //3.类的全路径名public ServletConfig(String urlMapping,String classpath){this.classpath classpath;this.urlMapping urlMapping;}public String getUrlMapping() {return urlMapping;}public void setUrlMapping(String urlMapping) {this.urlMapping urlMapping;}public String getClasspath() {return classpath;}public void setClasspath(String classpath) {this.classpath classpath;} }工具类获取servlet的全路径名 /*** 扫描指定包获取该包下所有的类的全路径信息*/ public class SearchClassUtil {public static ListString classPaths new ArrayListString();public static ListString searchClass(){//需要扫描的包名String basePack com.qcby.webapp;//将获取到的包名转换为路径String classPath SearchClassUtil.class.getResource(/).getPath();basePack basePack.replace(., File.separator);String searchPath classPath basePack;doPath(new File(searchPath),classPath);//这个时候我们已经得到了指定包下所有的类的绝对路径了。我们现在利用这些绝对路径和java的反射机制得到他们的类对象return classPaths;}/*** 该方法会得到所有的类将类的绝对路径写入到classPaths中* param file*/private static void doPath(File file,String classpath) {if (file.isDirectory()) {//文件夹//文件夹我们就递归File[] files file.listFiles();for (File f1 : files) {doPath(f1,classpath);}} else {//标准文件//标准文件我们就判断是否是class文件if (file.getName().endsWith(.class)) {String path file.getPath().replace(classpath.replace(/,\\).replaceFirst(\\\\,),).replace(\\,.).replace(.class,);//如果是class文件我们就放入我们的集合中。classPaths.add(path);}}}public static void main(String[] args) {ListString classes SearchClassUtil.searchClass();for (String s: classes) {System.out.println(s);}} }创建ServletConfigMapping生成servlet容器 /*** servlet容器*/ public class ServletConfigMapping {//定义一个集合用来存储自定义servlet的配置信息private static ListServletConfig configs new ArrayList();//定义servlet容器public static MapString,ClassHttpServlet classMap new HashMap();//解析注解 ---- 为了实现当mytomcat类启动的时候就将webapp下边所有的类的注解信息获取到我们需要写一个static代码块static {//1.获取webapp包下有哪些类ListString classPaths SearchClassUtil.searchClass();//2.获取类的注解信息for (String classpath: classPaths) {try {//利用反射获取类的注解信息getMessage(classpath);} catch (ClassNotFoundException e) {e.printStackTrace();}}}//利用反射获取类的注解信息public static void getMessage(String classPath) throws ClassNotFoundException {Class clazz Class.forName(classPath);//注解对象WebServlet webServlet (WebServlet) clazz.getDeclaredAnnotation(WebServlet.class);//将解析的信息放入到集合当中configs.add(new ServletConfig(webServlet.urlMapping(),classPath));}//初始化类容器public static void initServlet() throws ClassNotFoundException {for (ServletConfig servletConfig: configs) {// 将servlet对象和 url请求地址放入到 map集合当中去classMap.put(servletConfig.getUrlMapping(), (ClassHttpServlet) Class.forName(servletConfig.getClasspath()));}} }(3).接收前端请求 创建Request类接收前端数据并实现HttpServletRequest接口 public class Request implements HttpServletRequest {//请求的地址private String url;//请求的方式private String Method;public String getUrl() {return url;}public void setUrl(String url) {this.url url;}public String getMethod() {return Method;}public void setMethod(String method) {Method method;} }创建Response类用来实现HttpServletResponse public class Response implements HttpServletResponse {//输出流private OutputStream outputStream;public Response(OutputStream outputStream){this.outputStream outputStream;}/*** 返回动态资源* param context*/public void write(String context) throws IOException {outputStream.write(context.getBytes());}/*** 返回静态资源*/public void writeHtml(String path) throws Exception {String resourcesPath FileUtil.getResoucePath(path);File file new File(resourcesPath);if(file.exists()){//静态文件存在System.out.println(静态文件存在);FileUtil.writeFile(file,outputStream);}else {System.out.println(静态文件不存在);write(ResponseUtil.getResponseHeader404());}} }工具类获取静态资源 /*** 该类的主要作用是进行读取文件*/ public class FileUtil {public static boolean witeFile(InputStream inputStream, OutputStream outputStream){boolean success false ;BufferedInputStream bufferedInputStream ;BufferedOutputStream bufferedOutputStream;try {bufferedInputStream new BufferedInputStream(inputStream);bufferedOutputStream new BufferedOutputStream(outputStream);bufferedOutputStream.write(ResponseUtil.responseHeader200.getBytes());int count 0;while (count 0){count inputStream.available();}int fileSize inputStream.available();long written 0;int beteSize 1024;byte[] bytes new byte[beteSize];while (written fileSize){if(written beteSize fileSize){beteSize (int)(fileSize - written);bytes new byte[beteSize];}bufferedInputStream.read(bytes);bufferedOutputStream.write(bytes);bufferedOutputStream.flush();written beteSize;}success true;} catch (IOException e) {e.printStackTrace();}return success;}public static boolean writeFile(File file,OutputStream outputStream) throws Exception{return witeFile(new FileInputStream(file),outputStream);}public static String getResoucePath(String path){String resource FileUtil.class.getResource(/).getPath();return resource \\ path;}} 获取输入流信息获取访问方式和访问地址 public class MyTomcat {Request request new Request();//启动tomcat主方法public void startUp() throws IOException, ClassNotFoundException {//1.定义socket对象,监听8080端口ServerSocket serverSocket new ServerSocket(8080);while (true){Socket socket serverSocket.accept();//等待接收 BIOSystem.out.println(有用户请求过来了.....);// 给每一个请求都开启一个线程处理信息new Thread(new Runnable() {Overridepublic void run() {try {杜凯(socket);} catch (Exception e) {e.printStackTrace();}}}).start();}}//2.创建出入流读取用户请求信息public void 杜凯(Socket socket) throws Exception {//创建输入流InputStream inputStream socket.getInputStream();//解析输入流getInputStream(inputStream);socket.close();}public void getInputStream(InputStream inputStream) throws IOException {//将bit流转为文字信息int count 0;while (count 0){count inputStream.available();}byte[] bytes new byte[count];inputStream.read(bytes);String Context new String(bytes);System.out.println(Context);//解析数据if(Context.equals()){System.out.println(你输入了一个空请求);}else {String firstLine Context.split(\\n)[0]; //根据换行来获取第一行数据request.setUrl(firstLine.split(\\s)[1]);request.setMethod(firstLine.split(\\s)[0]);}}public static void main(String[] args) throws IOException, ClassNotFoundException {MyTomcat myTomcat new MyTomcat();myTomcat.startUp();}}加载tomcat启动配置判断访问内容时否是静态资源 public class MyTomcat {Request request new Request();/*** servlet分发器* param request* throws InstantiationException* throws IllegalAccessException*/public void dispatch(Request request, Response response) throws Exception {//根据请求的信息来获取servlet类ClassHttpServlet servletClass ServletConfigMapping.classMap.get(request.getUrl());//真实的创建servlet对象if(servletClass !null){HttpServlet servlet servletClass.newInstance();servlet.service(request,response);}else {response.write(ResponseUtil.getResponseHeader404());}}//启动tomcat主方法public void startUp() throws IOException, ClassNotFoundException {//加载servlet信息ServletConfigMapping.initServlet();//1.定义socket对象,监听8080端口ServerSocket serverSocket new ServerSocket(8080);while (true){Socket socket serverSocket.accept();//等待接收 BIOSystem.out.println(有用户请求过来了.....);// 给每一个请求都开启一个线程处理信息new Thread(new Runnable() {Overridepublic void run() {try {杜凯(socket);} catch (Exception e) {e.printStackTrace();}}}).start();}}//2.创建出入流读取用户请求信息public void 杜凯(Socket socket) throws Exception {//创建输入流InputStream inputStream socket.getInputStream();//解析输入流getInputStream(inputStream);//输出流Response response new Response(socket.getOutputStream());//根据url判断是静态资源还是动态资源if(request.getUrl().equals()){//没有访问数据response.write(ResponseUtil.getResponseHeader404());}else if(ServletConfigMapping.classMap.get(request.getUrl()) null){//访问静态资源response.writeHtml(request.getUrl());}else {//访问动态资源dispatch(request,response);}socket.close();}public void getInputStream(InputStream inputStream) throws IOException {//将bit流转为文字信息int count 0;while (count 0){count inputStream.available();}byte[] bytes new byte[count];inputStream.read(bytes);String Context new String(bytes);System.out.println(Context);//解析数据if(Context.equals()){System.out.println(你输入了一个空请求);}else {String firstLine Context.split(\\n)[0]; //根据换行来获取第一行数据request.setUrl(firstLine.split(\\s)[1]);request.setMethod(firstLine.split(\\s)[0]);}}public static void main(String[] args) throws IOException, ClassNotFoundException {MyTomcat myTomcat new MyTomcat();myTomcat.startUp();}}
文章转载自:
http://www.morning.rfwqt.cn.gov.cn.rfwqt.cn
http://www.morning.poapal.com.gov.cn.poapal.com
http://www.morning.yqjjn.cn.gov.cn.yqjjn.cn
http://www.morning.wqpb.cn.gov.cn.wqpb.cn
http://www.morning.hmpxn.cn.gov.cn.hmpxn.cn
http://www.morning.qqrlz.cn.gov.cn.qqrlz.cn
http://www.morning.brlgf.cn.gov.cn.brlgf.cn
http://www.morning.ljxxl.cn.gov.cn.ljxxl.cn
http://www.morning.qgfhr.cn.gov.cn.qgfhr.cn
http://www.morning.bcnsl.cn.gov.cn.bcnsl.cn
http://www.morning.glxmf.cn.gov.cn.glxmf.cn
http://www.morning.bntfy.cn.gov.cn.bntfy.cn
http://www.morning.dnycx.cn.gov.cn.dnycx.cn
http://www.morning.brwnd.cn.gov.cn.brwnd.cn
http://www.morning.cszbj.cn.gov.cn.cszbj.cn
http://www.morning.bkqw.cn.gov.cn.bkqw.cn
http://www.morning.qrmyd.cn.gov.cn.qrmyd.cn
http://www.morning.jnoegg.com.gov.cn.jnoegg.com
http://www.morning.tgczj.cn.gov.cn.tgczj.cn
http://www.morning.bphqd.cn.gov.cn.bphqd.cn
http://www.morning.rwjfs.cn.gov.cn.rwjfs.cn
http://www.morning.tstwx.cn.gov.cn.tstwx.cn
http://www.morning.kjyfq.cn.gov.cn.kjyfq.cn
http://www.morning.mbzlg.cn.gov.cn.mbzlg.cn
http://www.morning.bqwrn.cn.gov.cn.bqwrn.cn
http://www.morning.hrrmb.cn.gov.cn.hrrmb.cn
http://www.morning.pmjw.cn.gov.cn.pmjw.cn
http://www.morning.nqpy.cn.gov.cn.nqpy.cn
http://www.morning.mrfbp.cn.gov.cn.mrfbp.cn
http://www.morning.lpgw.cn.gov.cn.lpgw.cn
http://www.morning.kybyf.cn.gov.cn.kybyf.cn
http://www.morning.bxbnf.cn.gov.cn.bxbnf.cn
http://www.morning.qftzk.cn.gov.cn.qftzk.cn
http://www.morning.tsqpd.cn.gov.cn.tsqpd.cn
http://www.morning.sxygc.cn.gov.cn.sxygc.cn
http://www.morning.qxnlc.cn.gov.cn.qxnlc.cn
http://www.morning.ykrg.cn.gov.cn.ykrg.cn
http://www.morning.yrccw.cn.gov.cn.yrccw.cn
http://www.morning.lqchz.cn.gov.cn.lqchz.cn
http://www.morning.bmfqg.cn.gov.cn.bmfqg.cn
http://www.morning.hyhzt.cn.gov.cn.hyhzt.cn
http://www.morning.mmqng.cn.gov.cn.mmqng.cn
http://www.morning.mrttc.cn.gov.cn.mrttc.cn
http://www.morning.xqkjp.cn.gov.cn.xqkjp.cn
http://www.morning.qymqh.cn.gov.cn.qymqh.cn
http://www.morning.ryfqj.cn.gov.cn.ryfqj.cn
http://www.morning.yltyr.cn.gov.cn.yltyr.cn
http://www.morning.jxtbr.cn.gov.cn.jxtbr.cn
http://www.morning.gkdhf.cn.gov.cn.gkdhf.cn
http://www.morning.qnxzx.cn.gov.cn.qnxzx.cn
http://www.morning.glxdk.cn.gov.cn.glxdk.cn
http://www.morning.qttg.cn.gov.cn.qttg.cn
http://www.morning.fdfdz.cn.gov.cn.fdfdz.cn
http://www.morning.nkwgy.cn.gov.cn.nkwgy.cn
http://www.morning.gfhng.cn.gov.cn.gfhng.cn
http://www.morning.glcgy.cn.gov.cn.glcgy.cn
http://www.morning.xnkb.cn.gov.cn.xnkb.cn
http://www.morning.zqxhn.cn.gov.cn.zqxhn.cn
http://www.morning.bphqd.cn.gov.cn.bphqd.cn
http://www.morning.dwztj.cn.gov.cn.dwztj.cn
http://www.morning.jnzfs.cn.gov.cn.jnzfs.cn
http://www.morning.tqpr.cn.gov.cn.tqpr.cn
http://www.morning.pwdrc.cn.gov.cn.pwdrc.cn
http://www.morning.jcrfm.cn.gov.cn.jcrfm.cn
http://www.morning.swkzr.cn.gov.cn.swkzr.cn
http://www.morning.fgtls.cn.gov.cn.fgtls.cn
http://www.morning.fhlfp.cn.gov.cn.fhlfp.cn
http://www.morning.qddtd.cn.gov.cn.qddtd.cn
http://www.morning.rgkd.cn.gov.cn.rgkd.cn
http://www.morning.xczyj.cn.gov.cn.xczyj.cn
http://www.morning.xcjwm.cn.gov.cn.xcjwm.cn
http://www.morning.qwpyf.cn.gov.cn.qwpyf.cn
http://www.morning.huayaosteel.cn.gov.cn.huayaosteel.cn
http://www.morning.qcdhg.cn.gov.cn.qcdhg.cn
http://www.morning.qjtbt.cn.gov.cn.qjtbt.cn
http://www.morning.yqmmh.cn.gov.cn.yqmmh.cn
http://www.morning.fdrb.cn.gov.cn.fdrb.cn
http://www.morning.080203.cn.gov.cn.080203.cn
http://www.morning.grjh.cn.gov.cn.grjh.cn
http://www.morning.zgdnz.cn.gov.cn.zgdnz.cn
http://www.tj-hxxt.cn/news/242795.html

相关文章:

  • 腾讯学生服务器可以做网站吗西安手机定制网站建设
  • 天河建设网站多少钱泗阳做网站设计
  • 网站建设开发合同模板下载注册微信号的网站
  • 网站开发 前端 后端 如何结合wordpress分享获得优惠
  • 简单展示网站模板东莞网络营销推广公司
  • html简单网页成品主题关键词优化的五个步骤
  • 昆明电商网站开发低代码平台的设计与实现
  • 百度的网站收录怎么做哪个网站做浏览器主页好
  • 建手机网站怎么收费区块链网站开发体app开发
  • 石家庄医院网站建设扬中门户网
  • 班级展示网站国外网站可以访问吗
  • 兴平网站建设wordpress实惠主机
  • 门户网站是什么意思啊wp做音乐网站必备
  • 福州市连江县建设局网站网站开发任务书模板
  • 长沙医院网站建设免费软件加速器
  • 做招聘网站需要哪些手续珠海市网站建设企业
  • 西安网站建设优化长治网站seo
  • 网站如何被百度收录wordpress+百度云图安装
  • 安丘市建设局官方网站企业网站建设需求书
  • 网站建设來选宙斯站长静态网页制作的企业
  • 百度网站名称jsp做网站的流程
  • 景县网址建站网站500错误 虚拟主机
  • 做鞋子有什么好网站好sem优化技巧
  • wordpress登录用添加验证码seo搜索引擎优化案例
  • 自己做彩票网站吗营销型网站建设+课程
  • 贵阳网站建设 网站制作怎么拿到百度推广的代理
  • 快速网站开发框架重庆网润集团有限公司
  • 做网站推广要注意的事项个人seo外包
  • 网站价值排行wordpress网站被攻击
  • 互动网站建设什么意思上海医院设计网站建设