Body{font-size:100%;}是设置body字体大小为浏览器默认字体吗?

然后我们将body下的标签的font-size属性都设置为以em为单位,就可以在不放缩页面大小的情况下,改变字体的大小了。

如:

<style>
      body {font-size:100%;}
         p {font-size:0.8em;}
</style>
  1. 当浏览器的默认字体改为16px时,body的也为16px;同理15px时也就是15px了,时这样吗?
    2.这是不是实现字体可调整大小的最好方式?有什么不足吗?

盼指点。(C币已空、、= =,不要走!)

1个回答

font-size:100% 是将字体大小设置成默认大小,即继承父元素的字体大小设置。

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
其他相关推荐
同时使用background-size:cover和background-attachment:fixed图片显示效果改变的原因
``` <html> <head> <style> body,ul,li{margin: 0; padding: 0;} .wrap{ width: 100%; height: 60px; } .img{ width: 100%; height: 60px; background-image: url(1.jpg); background-repeat: no-repeat; background-size: cover; background-attachment: fixed; } </style> </head> <body> <div class="wrap"> <div class="img"></div> </div> </body> </html> ```
css中的一些不起作用,但放在HTML中起作用,为啥呢求解决。。。
@CHARSET "UTF-8"; <style> h1{ background-color: #ADD8e6; color: #256579; font:18px Verdana,Geneva,Arial,Helvetica,sans-serif; padding:2px; border-bottom:1px solid #aaaaaa; } body{ background-color: #ffffff; background-image: url(images/sb.jpg); background-repeat: repeat-x; } .one{ font-family:隶书; font-size:24px; color:red; } .two{ font-family:宋体; font-size:18px; color:red; } .three{ font-family:宋体; font-size:12px; color:red; } </style> ``` ```h1和body不管用,one,two,等管用,h1和body放在HTML中起作用,在css中不管用,求解决。。谢大神
背景图片,图片,跑到别的div,页面最下面有空白
body{ padding: 0; margin:0; overflow-x:hidden; } .name{ position: absolute; right: 60px; font-size:50px; } .nav li a:link{ color: black; text-decoration: none; } .nav li{ display: inline; color: black; position: relative; left: 350px; font-size: 22px; } #a2{ height: 100px; background-image: url(images/1.jpg); } #a2 h2{ color: white; font-size: 60px; margin: 0 auto; position: relative; left: 500px; line-height: 100px; font-family: "微软雅黑"; } #a3 h3{ position: relative; left: 500px; font-family: "agency fb"; font-size: 50px; } #a41{ font-size: 20px; float: left; } #a41 img{ width: 445px; height: 200px; } #a41 p{ width:445px; font-size: 15px; text-align: center; } #a5{ height: 400px; background-image:url(images/1.jpg); } #a51 { font-size: 20px; display: inline; width: 455px; color: black; } #a6{ position: relative; top: 60px; left: 260px; } #a61{ float: left; } #a61 img{ width: 200px; height: 330px; } #a61 p{ color: black; font-size: 15px; text-align: center; } .box{ height: ; position: relative ; top: 60px; background-color:gray; clear: both; color: white; height: 300px; } span{ position: relative; left: 200px; top: 100px; font-size: 40px; } .small{ font-size: 20px; } .box li{ line-height:30px ; } .box ul{ list-style-type: none; position: relative; left: 500px; } .box a:link{ color: white; font-size: 15px; text-decoration: none; } section{ position:relative; left: 120px; bottom: 115px; } .box p:first-child{ font-size: 30px; } .box p{ position: relative; left: 960px; bottom: 280px; } .one{ font-size:14px; background-color: black; color: white; } input{ position: relative; left: 960px; bottom: 280px; } ul{ padding: 0; ![图片说明](https://img-ask.csdn.net/upload/201710/27/1509072579_163422.png)![![![![![图片说明](https://img-ask.csdn.net/upload/201710/27/1509072669_550296.png)图片说明](https://img-ask.csdn.net/upload/201710/27/1509072656_698275.png)图片说明](https://img-ask.csdn.net/upload/201710/27/1509072639_408512.png)图片说明](https://img-ask.csdn.net/upload/201710/27/1509072619_806431.png)图片说明](https://img-ask.csdn.net/upload/201710/27/1509072540_675283.png)
@RequestBody 实体类接收不到数据,但是用com.alibaba.fastjson.JSONObject可以
``` @RequestMapping(value = "/getTest", method = {RequestMethod.POST}) public @ResponseBody CommonResponse getTest(@RequestBody TestForm form { ``` 后台这样写,使用postman测试 请求会直接报400, ``` <!doctype html> <html lang="en"> <head> <title>HTTP Status 400 – Bad Request</title> <style type="text/css"> h1 { font-family: Tahoma, Arial, sans-serif; color: white; background-color: #525D76; font-size: 22px; } h2 { font-family: Tahoma, Arial, sans-serif; color: white; background-color: #525D76; font-size: 16px; } h3 { font-family: Tahoma, Arial, sans-serif; color: white; background-color: #525D76; font-size: 14px; } body { font-family: Tahoma, Arial, sans-serif; color: black; background-color: white; } b { font-family: Tahoma, Arial, sans-serif; color: white; background-color: #525D76; } p { font-family: Tahoma, Arial, sans-serif; background: white; color: black; font-size: 12px; } a { color: black; } a.name { color: black; } .line { height: 1px; background-color: #525D76; border: none; } </style> </head> <body> <h1>HTTP Status 400 – Bad Request</h1> <hr class="line" /> <p><b>Type</b> Status Report</p> <p><b>Description</b> The server cannot or will not process the request due to something that is perceived to be a client error (e.g., malformed request syntax, invalid request message framing, or deceptive request routing). </p> <hr class="line" /> <h3>Apache Tomcat/8.5.42</h3> </body> </html> ``` 如果后台改为 ``` public CommonResponse getTest(@RequestBody JSONObject jsonObject) { ``` 用JSONObject接收则没有问题,请各位大佬告知原因
html里面搞了几个div,却无法进行翻页操作,怎么办?
css代码如下: body{ margin-top:0px; overflow:cover; background-color: hsl(0, 17%, 93%); } .logo{ position: fixed; width: 35%; height:auto; left: 10px; top: 15px; float:left; margin-top: 0px; top:0%; left:10%; } #box{ margin:0 auto; width:998px; background-color:white; text-align: center; font-size:13px; color:#333333; border:0px solid red; height:100%; overflow:hidden; } #menu{ width:998px; height:33px; color:#000066; font-size:14px; padding-top:8px; /**background-image: url("");**/ text-align:center; position: fixed; left:10%; top:150px; } #gundong-img{ background-image: url("ddf55l2f8m.jpg"); background-repeat: no-repeat; background-size: 90% auto; width:40%; height:50%; position:fixed; left:10%; top:300px; } #gundong-text{ background-color: darkorange; color:white; position:fixed; left:10%; top:600px; align-self: center; } 这几个东西应用到div里面,发现太长了,然而打开网页后不能滚动页面,qiu'jie'j
css设置了背景图片会随浏览器页面缩小而缩小,如何设置它被缩小后的最小宽度
body{ position: absolute; width:100%; height:100%; margin: 0px; padding: 0px; background-image:url("chengping3.jpg"); background-repeat: no-repeat; background-size:80% auto; background-position: top center; background-attachment:scroll; background-color: hsl(0, 17%, 93%); text-align:center; } 第一次写,啥都不会 希望图片在浏览器框框缩小的时候,缩小到一定宽度就不能再缩小了,同时要保证原来的宽高比
javascript中传值的问题
<html><head><meta http-equiv="refresh" content="60"><title>单片机网络</title> [color=red]<script language="text/javascript"> function modify(){ var s=document.getElementById("m").value; return s; } </script>[/color] </head> <body bgcolor="#FFCC99" lang=ZH-CN style='text-justify-trim:punctuation'><br> <p class=MsoNormal align=center style='text-align:center'><span style='font-size:24.0pt;font-family:宋体'>单片机网络温度监视主页</span></p><br> <p class=MsoNormal align=center style='text-align:center'><span lang=EN-US style='font-size:24.0pt'>&nbsp;</span></p><br> <p class=MsoNormal align=center style='text-align:center'><span style='font-size:24.0pt;font-family:宋体'>节点</span> <span lang=EN-US style='font-size:36.0pt;color:#FF5050'>001</span> <span style='font-size:24.0pt;font-family:宋体'>的温度是</span> <span lang=EN-US style='font-size:36.0pt;color:#0000FF'> 00.0 <span lang=EN-US style='font-size:24.0pt;font-family:宋体;color:#FF0000'><span lang=EN-US>℃</span></span></span></p><br> <p class=MsoNormal align=center style='text-align:center'><span style='font-size:24.0pt;font-family:宋体'>节点</span> <span lang=EN-US style='font-size:36.0pt;color:#FF5050'>001</span> <span style='font-size:24.0pt;font-family:宋体'>的设定温度值:</span> <span lang=EN-US style='font-size:36.0pt;color:#0000FF'> [color=red]<script language="text/javascript"> document.write(modify()); </script>[/color] </span> <span lang=EN-US style='font-size:24.0pt;font-family:宋体;color:#FF0000'><span lang=EN-US>℃</span></span></span></p><br/> <p class=MsoNormal align=center style='text-align:center'><span style='font-size:24.0pt;font-family:宋体'>修改节点</span> <span lang=EN-US style='font-size:36.0pt;color:#FF5050'>001</span> <span style='font-size:24.0pt;font-family:宋体'>的温度值:</span> <input id="m" type="text" name="modifytxt"></input> <span lang=EN-US style='font-size:24.0pt;font-family:宋体;color:#FF0000'><span lang=EN-US>℃</span></span> <input type="button" onClick="modify()" value="确定"></input> </p> </body> </html> 说明:我就想在红色部分输出变量S的值,这个值是从id="m"的文本框里输入得到的,请各位大牛们指点一下!
对a标签设置字体大小的时候会如何影响包容他的p标签的外边距和高度?
当我分别在css中的p选择器中设置font-size:12px;和p a选择器设置font-size:12px;时,p标签的高度改变,外边距也发生了改变,这是为什么? 这是html代码: ``` <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <title>家用电器分类</title> <link href="css/type.css" rel="stylesheet" type="text/css" /> </head> <body> <div id="type"> <div id="title">家用电器</div> <div class="secondTitle"><a href="#">大家电</a></div> <p><a href="#">平板电视</a> <a href="#">洗衣机</a> <a href="#">冰箱</a><br/> <span> </span><a href="#">空调</a> <a href="#">烟机/灶具</a> <a href="#">热水器</a><br/> <span> </span><a href="#">冷柜/酒柜</a> <a href="#">消毒柜</a> <a href="#">家庭影院</a></p> </div> </body> </html> ``` 这是css代码: ``` @charset "gb2312"; /* CSS Document */ #type { width:800px; } #title { font-size:18px; text-indent:1em; background-color:#0f7cbf; line-height:35px; color:#FFF; font-weight:bold; } .secondTitle { background-color:#e4f1fa; text-indent:2em; font-size:14px; line-height:30px; font-weight:bold; } .secondTitle a { color:#0f7cbf; text-decoration:none; } .secondTitle a:hover { text-decoration:underline; } p { line-height:20px; text-indent:1em; } p a { font-size:12px; color:#666666; text-decoration:none; } p a:hover { color:#F60; text-decoration:underline; } ```
帮我看下这个网页中的三个图片div的大小和位置怎么更改设置
我想更换几张大图,但是无论放多大的图片都会局限在这个边框里,怎么样才能更改所放图片的大小和位置呢? ![图片说明](https://img-ask.csdn.net/upload/201912/25/1577260837_900227.png) 下边的图其实我放了一张很大的图,但是都会按比例缩放到这个位置,怎么才能更改默认图片的长宽?和位置? ![图片说明](https://img-ask.csdn.net/upload/201912/25/1577260847_818926.png) ``` <!DOCTYPE html> <html lang="zh"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>CSS3鼠标悬停图片遮罩层动画特效</title> <!--bootstrap布局框架--> <link rel="stylesheet" type="text/css" href="css/bootstrap-grid.min.css" /> <!--字体图标样式--> <link rel="stylesheet" type="text/css" href="https://cdn.bootcss.com/font-awesome/4.6.0/css/font-awesome.min.css"> <style> body{background-color: #353535} .box { font-family: 'Ubuntu', sans-serif; overflow: hidden; position: relative; transition: all 0.3s; } .box:hover { box-shadow: 0 0 15px -5px #000; } .box:before { content: ''; background-color: transparent; background-image: radial-gradient(circle at 20% 80%, transparent 29%, rgba(255,255,255,0.4) 30%, rgba(255,255,255,0.4) 33%, transparent 34%), radial-gradient(circle at 80% 20%, transparent 29%, rgba(255,255,255,0.4) 30%, rgba(255,255,255,0.4) 33%, transparent 34%); background-size: 30px 30px; height: 100%; width: 100%; opacity: 0; position: absolute; left: 0; top: 0; z-index: 1; transition: all 0.3s ease 0.2s; } .box:hover:before { opacity: 1; } .box img { width: 100%; height: auto; transition: all 0.3s ease 0s; } .box:hover img { filter: blur(2px); } .box .box-content { color: #fff; background-color: rgba(0,0,0,0.6); text-align: center; width: 100%; height: 59%; padding: 18% 0 0 0; position: absolute; left: 0; top: -100%; z-index: 2; transition: all 0.3s ease 0s; } .box:hover .box-content { top: 0; } .box .title { color: #fff; font-size: 23px; font-weight: 600; letter-spacing: 1px; text-transform: uppercase; margin: 0; } .box .post { color: #32c287; font-size: 14px; font-style: italic; text-transform: capitalize; letter-spacing: 2px; } .box .icon { background: rgba(50,194,135,0.6); text-align: center; height: 39%; width: 100%; padding: 15px 0 0; margin: 0; list-style: none; transform: translateX(50%); position: absolute; right: 50%; bottom: -100%; z-index: 1; transition: all 0.3s; } .box:hover .icon { bottom: 0; } .box .icon li { display: inline-block; margin: 0 3px; } .box .icon li a { color: #32c287; background-color: #fff; font-size: 18px; line-height: 40px; height: 40px; width: 40px; border-radius: 40%; display: block; transition: all 0.3s; } .box .icon li a:hover { color: #fff; background-color: #04a562; box-shadow: 0 0 0 3px rgba(255,255,255,0.5), 0 0 5px rgba(0,0,0,0.5) inset; } @media only screen and (max-width:990px) { .box { margin-bottom: 30px; } } @media only screen and (max-width:479px) { .box .title { font-size: 20px; } } </style> </head> <body> <h4 style="text-align: center; color: aliceblue;line-height: 50px">CSS3图片鼠标悬停动画特效 <span>Hover Effect Style</span></h4> <div class="demo"> <div class="container"> <div class="row"> <div class="col-md-4 col-sm-6"> <div class="box"> <img src="images/img-1.jpg" alt=""> <div class="box-content"> <h3 class="title">餐饮软件</h3> <span class="post">web developer</span> </div> <ul class="icon"> <li><a href="#"><i class="fa fa-search"></i></a></li> <li><a href="#"><i class="fa fa-link"></i></a></li> </ul> </div> </div> <div class="col-md-4 col-sm-6"> <div class="box"> <img src="images/img-2.jpg" alt=""> <div class="box-content"> <h3 class="title">零售软件</h3> <span class="post">web designer</span> </div> <ul class="icon"> <li><a href="#"><i class="fa fa-search"></i></a></li> <li><a href="#"><i class="fa fa-link"></i></a></li> </ul> </div> </div> <div class="col-md-4 col-sm-6"> <div class="box"> <img src="images/img-3.jpg" alt=""> <div class="box-content"> <h3 class="title">会员系统</h3> <span class="post">web developer</span> </div> <ul class="icon"> <li><a href="#"><i class="fa fa-search"></i></a></li> <li><a href="#"><i class="fa fa-link"></i></a></li> </ul> </div> </div> </div> </div> </div> <div style="text-align:center;margin:50px 0; font:normal 14px/24px 'MicroSoft YaHei';color:#ffffff"> <p>适用浏览器:360、FireFox、Chrome、Opera、傲游、搜狗、世界之窗. 不支持Safari、IE8及以下浏览器。</p> <p>来源:<a href="https://www.lanrenzhijia.com/" target="_blank">懒人</a></p> </div> </body> </html> ```
page-break-after: always;火狐浏览器上不执行
``` <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> <title>分页打印</title> </head> <body> <object id=WebBrowser classid=CLSID:8856F961-340A-11D0-A96B-00C04FD705A2 height=0 width=0 ></object> <table border="0" style="font-size:9pt;" width="300px" align="center"> <thead style="display:table-header-group; font-weight:bold"> <tr> <td colspan="2" align="center" style="font-weight:bold; border:3px double red"> 每页都有的表头 </td> </tr> </thead> <tbody> <tr><td>表格内容</td><td>表格内容</td></tr> <tr><td>表格内容</td><td>表格内容</td></tr> <tr><td>表格内容</td><td>表格内容</td></tr> <tr><td>表格内容</td><td>表格内容</td></tr> <tr style=" page-break-after : always;"> <td>在这个之后分页</td> <td>在这个之后分页</td> </tr> <tr><td>表格内容</td><td>表格内容</td></tr> <tr><td>表格内容</td><td>表格内容</td></tr> <tr><td>表格内容</td><td>表格内容</td></tr> <tr><td>表格内容</td><td>表格内容</td></tr> <tr><td>表格内容</td><td>表格内容</td></tr> </tbody> <tfoot style="display:table-footer-group; font-weight:bold"> <tr> <td colspan="2" align="center" style="font-weight:bold; border:3px double blue"> 每页都有的表尾 </td> </tr> </tfoot> </table> <div align="center"> <input type="button" value="打 印" onclick="javascript:window.print()" /> </div> </body> </html> ``` page-break-after: always;火狐不执行。IE上面却可以。怎么做兼容 ![图片说明](https://img-ask.csdn.net/upload/201501/05/1420455885_690618.png)
证件识别接口 java调用及实现
证件识别接口 ,调用了post方法,但没有结果,result=<html><head><title>Apache Tomcat/7.0.57 - Error report</title><style><!--H1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} H2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} H3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} BODY {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} B {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} P {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;}A {color : black;}A.name {color : black;}HR {color : #525D76;}--></style> </head><body><h1>HTTP Status 404 - /cardrecon/upload</h1><HR size="1" noshade="noshade"><p><b>type</b> Status report</p><p><b>message</b> <u>/cardrecon/upload</u></p><p><b>description</b> <u>The requested resource is not available.</u></p><HR size="1" noshade="noshade"><h3>Apache Tomcat/7.0.57</h3></body></html>显然是错了,但不懂哪里出错,求指导
VC6 curl https post 发json返回问题
用vc6,curl库进行https的post请求发送json数据,我访问的网址是https的,需要通过VPN连接上的,返回如下: HTTP/1.1 400 Bad Request 返回::HTTP/1.1 400 Bad Request Server: nginx Date: Sat, 21 Oct 2017 10:20:10 GMT Content-Type: text/html;charset=utf-8 Content-Length: 968 Connection: keep-alive <html><head><title>Apache Tomcat/6.0.37 - Error report</title><style><!--H1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} H2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} H3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} BODY {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} B {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} P {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;}A {color : black;}A.name {color : black;}HR {color : #525D76;}--></style> </head><body><h1>HTTP Status 400 - </h1><HR size="1" noshade="noshade"><p><b>type</b> Status report</p><p><b>message</b> <u></u></p><p><b>description</b> <u>The request sent by the client was syntactically incorrect.</u></p><HR size="1" noshade="noshade"><h3>Apache Tomcat/6.0.37</h3></body></html> 请知道的大神给个解决办法。
求大佬帮忙看看,表格导出excel问题。
1. 使用js导出excel时 如果页面的表格中数据较少时 excel会打不开。 下面是导出表格的js ``` //base64转码 var base64 = function(s) { return window.btoa(unescape(encodeURIComponent(s))); }; //替换table数据和worksheet名字 var format = function(s, c) { return s.replace(/{(\w+)}/g, function(m, p) { return c[p]; }); } function tableToExcel(tableid, sheetName, fileName) { var table; var uri = 'data:application/vnd.ms-excel;base64,'; var template = '<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel"' + 'xmlns="http://www.w3.org/TR/REC-html40"><head><!--[if gte mso 9]><xml><x:ExcelWorkbook><x:ExcelWorksheets><x:ExcelWorksheet>' + '<x:Name>{worksheet}</x:Name><x:WorksheetOptions><x:DisplayGridlines/></x:WorksheetOptions></x:ExcelWorksheet></x:ExcelWorksheets>' + '</x:ExcelWorkbook></xml><![endif]-->' + ' <style type="text/css">' + 'table td {' + 'border: 1px solid #d6d6d6;' + 'width: 200px;' + 'height: 30px;' + ' text-align: center;' + 'background-color: #ffffff;' + 'color: #000;' + ' }' + '</style>' + '</head><body ><table class="excelTable">{table}</table></body></html>'; if (!tableid.nodeType) { table = $("#" + tableid).clone(); table.find("th").each(function(){ if($(this).css("display")=="none"){ $(this).remove(); } }); table.find("td").each(function(){ if($(this).css("display")=="none"){ $(this).remove(); } }); } var ctx = { worksheet : sheetName || 'Worksheet', table : table[0].innerHTML }; document.getElementById("excelOut").href = uri + base64(format(template, ctx)); document.getElementById("excelOut").download = fileName; document.getElementById("excelOut").click(); } ``` 1. 下面是导出的表格的文本代码 ``` <html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel"xmlns="http://www.w3.org/TR/REC-html40"><head><!--[if gte mso 9]><xml><x:ExcelWorkbook><x:ExcelWorksheets><x:ExcelWorksheet><x:Name>xxxx</x:Name><x:WorksheetOptions><x:DisplayGridlines/></x:WorksheetOptions></x:ExcelWorksheet></x:ExcelWorksheets></x:ExcelWorkbook></xml><![endif]--> <style type="text/css">table td {border: 1px solid #d6d6d6;width: 200px;height: 30px; text-align: center;background-color: #ffffff;color: #000; }</style></head><body ><table class="excelTable"> <thead> <tr class="content_grid_title"> <th height="40px;" style="font-size:14px;color:#404040;border:1px solid #ccc">柜面名称</th> <th style="font-size:14px;color:#404040; border:1px solid #ccc">回路名称</th> <th style="font-size:14px;color:#404040;border:1px solid #ccc">相电压越上限</th> <th style="font-size:14px;color:#404040;border:1px solid #ccc">相电压越下下限</th> <th style="font-size:14px;color:#404040;border:1px solid #ccc">汇总</th></tr> <tr class="content_grid_title"></tr> </thead> <tbody><tr><td style="font-size:14px;color:#404040 ;border:1px solid #ccc;height:40px">AA1-AA4</td><td style="font-size:14px;color:#404040 ;border:1px solid #ccc;height:40px">3AA-1</td><td style="font-size:14px;color:#404040 ;border:1px solid #ccc;height:40px">1</td><td style="font-size:14px;color:#404040 ;border:1px solid #ccc;height:40px">0</td><td style="font-size:14px;color:#404040 ;border:1px solid #ccc;height:40px">1</td></tr><tr><td style="font-size:14px;color:#404040 ;border:1px solid #ccc;height:40px">3AA</td><td style="font-size:14px;color:#404040 ;border:1px solid #ccc;height:40px">3AA-4</td><td style="font-size:14px;color:#404040 ;border:1px solid #ccc;height:40px">2</td><td style="font-size:14px;color:#404040 ;border:1px solid #ccc;height:40px">1</td><td style="font-size:14px;color:#404040 ;border:1px solid #ccc;height:40px">3</td></tr><tr><td style="font-size:14px;color:#404040 ;border:1px solid #ccc;height:40px">AA8-AA12</td><td style="font-size:14px;color:#404040 ;border:1px solid #ccc;height:40px">11AA-1</td><td style="font-size:14px;color:#404040 ;border:1px solid #ccc;height:40px">0</td><td style="font-size:14px;color:#404040 ;border:1px solid #ccc;height:40px">1</td><td style="font-size:14px;color:#404040 ;border:1px solid #ccc;height:40px">1</td></tr></tbody> </table></body></html> ``` 此时excel不能正常打开 当tbody'中的数据多复制几份 就可以正常打开了。
li标签为啥去掉list-style-type:none;后,width就不起作用了呢?
代码如下,详细问题在代码注释边 ``` #topnav{ height:36px; background-color:silver; border: 1px solid seagreen; } #topnav ul{ /*line-height:30px;*/ margin: 5px; padding: 0px; border-bottom: solid; border-bottom-width: 2px; border-bottom-color: darkgreen; float :left; list-style-type: none; } #topnav li{ float: left; padding: 0px; list-style-type: none;/*为何没有它后,宽度失效了?*/ width: 62px; text-align: center; margin: 0px 0px 0px 5px; border: 2px solid darksalmon; background-color: mediumorchid; } #topnav li a{ font-family:arial; padding: 4px;/*想要使得块状区域更大些,但并没有啥作用,把display: block;去掉后,就会超出li标签的宽度,这是怎么回事*/ text-decoration:none; color:tan; display: block; } #topnav li a:hover{ background-color: khaki; color: darkcyan; } #topnav li#select { background-color: darkorange; background-repeat :no-repeat; } </style> </head> <body> <div id ="topnav"> <ul> <li id="select"><a href ="#">jlajla</a></li> <li><a href ="#">jlajla</a></li> <li><a href ="#">jlajla</a></li> <li><a href ="#">jlajla</a></li> </ul> </div> </body> ```
Java-Servlet线程安全问题
<p>在看zwchen很久之前的一篇博客,地址如下<br><br>http://zwchen.iteye.com/blog/91088<br><br>做了个测试,按照第一种做法</p> <p> </p> <p>为使用synchronized,<span style="color: #ff0000;"><strong>并未出现 线程共享情况</strong></span>,(我使用的是tomcat6.0带的servlet包)数据都是</p> <p> </p> <p>SimpleServlet@c4fe76 ==&gt; Thread[http-8080-1,5,main]: <br>Counter = 60<br>Counter = 61<br>Counter = 62<br>Counter = 63<br>Counter = 64<br>Counter = 65<br>Counter = 66<br>Counter = 67<br>Counter = 68<br>Counter = 69</p> <p> </p> <p><span style="font-family: Simsun; font-size: small;">SimpleServlet@c4fe76 ==&gt; Thread[http-8080-1,5,main]: <br>Counter = 70<br>Counter = 71<br>Counter = 72<br>Counter = 73<br>Counter = 74<br>Counter = 75<br>Counter = 76<br>Counter = 77<br>Counter = 78<br>Counter = 79</span></p> <p> </p> <p>SimpleServlet@c4fe76 ==&gt; Thread[http-8080-1,5,main]: <br>Counter = 80<br>Counter = 81<br>Counter = 82<br>Counter = 83<br>Counter = 84<br>Counter = 85<br>Counter = 86<br>Counter = 87<br>Counter = 88<br>Counter = 89</p> <p> </p> <p>正常输出。 请问各位高手,这个是为什么??</p> <p> </p> <p> </p> <p><span style="color: #ff0000;"><strong>还有,其中的</strong></span></p> <p><span style="font-family: Monaco, 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', Consolas, 'Courier New', monospace; line-height: 18px; background-color: #fafafa;"><span style="color: #ff0000;"><strong><span class="keyword" style="color: #7f0055; font-weight: bold;">synchronized</span><span style="color: black;"> (mutex)  为什么要用mutex这个参数?</span></strong></span></span></p> <p> </p> <p>我认为<span style="color: #7f0055; font-family: Monaco, 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', Consolas, 'Courier New', monospace; font-weight: bold; line-height: 18px; background-color: #fafafa;">synchronized的参数是表明同步的是哪块,所以我</span>改成  我自己servlet中的req,也可以正常跑</p> <p> </p> <p>public void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException</p> <p>       {</p> <p> </p> <p>  <span style="font-family: Monaco, 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', Consolas, 'Courier New', monospace; line-height: 18px; background-color: #fafafa;"><span class="keyword" style="color: #7f0055; font-weight: bold;">synchronized</span><span style="color: black;"> </span><span style="color: black;">(req) </span></span></p> <p> </p> <p> </p> <p><span style="color: #ff0000;"><strong>另外 ,最关键的:Thread.sleep((long) Math.random() * 1000);</strong></span></p> <p><span style="color: #ff0000;"><strong>我改成Thread.sleep(1000);,输出的结果就好像是线程共享了??</strong></span></p> <p> </p> <p> </p> <p> </p> <p>SimpleServlet@64883c ==&gt; Thread[http-8080-3,5,main]: <br>Counter = 4<br>Counter = 6<br>Counter = 10<br>Counter = 14<br>Counter = 18<br>Counter = 22<br>Counter = 26<br>Counter = 30<br>Counter = 34<br>Counter = 38</p> <p> </p> <p> </p> <p>SimpleServlet@64883c ==&gt; Thread[http-8080-6,5,main]: <br>Counter = 4<br>Counter = 7<br>Counter = 11<br>Counter = 15<br>Counter = 19<br>Counter = 23<br>Counter = 27<br>Counter = 31<br>Counter = 35<br>Counter = 39</p> <p> </p> <p>SimpleServlet@64883c ==&gt; Thread[http-8080-7,5,main]: <br>Counter = 4<br>Counter = 8<br>Counter = 12<br>Counter = 16<br>Counter = 20<br>Counter = 24<br>Counter = 28<br>Counter = 32<br>Counter = 36<br>Counter = 40</p> <p> </p> <p> </p> <p>下面附上  ZWCHEN先生的原文,并对他表示深深的敬意,谢谢!</p> <p><span style="font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 25px;"> </span></p> <div class="dp-highlighter" style="font-family: Monaco, 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', Consolas, 'Courier New', monospace; font-size: 12px; background-color: transparent; width: 694px; margin-left: 9px; padding: 1px;"> <div class="bar"> <div class="tools" style="text-align: left; color: black; font-weight: bold; padding: 3px; margin: 0px;">Java代码  <object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0" width="14" height="15"> <param name="src"> <embed type="application/x-shockwave-flash" width="14" height="15" src="http://zwchen.iteye.com/javascripts/syntaxhighlighter/clipboard_new.swf"></embed></object>  <a style="color: #108ac6; text-decoration: underline;" title="收藏这段代码" href="http://zwchen.iteye.com/blog/91088"><img class="star" style="border-color: initial;" src="http://zwchen.iteye.com/images/icon_star.png" alt="收藏代码"></a> </div> </div> <ol class="dp-j" style="font-size: 1em; line-height: 1.4em; margin-top: 0px; margin-right: 0px; margin-bottom: 1px; margin-left: 0px; padding-top: 2px; padding-right: 0px; padding-bottom: 2px; padding-left: 0px; background-color: #ffffff; color: #2b91af; border: 1px solid #d1d7dc;"> <li style="font-size: 1em; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 38px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: black;"><span class="keyword" style="color: #7f0055; font-weight: bold;">public</span><span style="color: black;"> </span><span class="keyword" style="color: #7f0055; font-weight: bold;">class</span><span style="color: black;"> SimpleServlet </span><span class="keyword" style="color: #7f0055; font-weight: bold;">extends</span><span style="color: black;"> HttpServlet  </span></span></li> <li style="font-size: 1em; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 38px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: black;">  </span></li> <li style="font-size: 1em; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 38px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: black;">{  </span></li> <li style="font-size: 1em; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 38px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: black;">       <span class="comment" style="color: #008200;">// A variable that is NOT thread-safe!</span><span style="color: black;">  </span></span></li> <li style="font-size: 1em; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 38px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: black;">       <span class="keyword" style="color: #7f0055; font-weight: bold;">private</span><span style="color: black;"> </span><span class="keyword" style="color: #7f0055; font-weight: bold;">int</span><span style="color: black;"> counter = </span><span class="number" style="color: #c00000;">0</span><span style="color: black;">;  </span></span></li> <li style="font-size: 1em; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 38px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: black;">       <span class="keyword" style="color: #7f0055; font-weight: bold;">public</span><span style="color: black;"> </span><span class="keyword" style="color: #7f0055; font-weight: bold;">void</span><span style="color: black;"> doGet(HttpServletRequest req, HttpServletResponse resp) </span><span class="keyword" style="color: #7f0055; font-weight: bold;">throws</span><span style="color: black;"> ServletException, IOException  </span></span></li> <li style="font-size: 1em; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 38px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: black;">       {  </span></li> <li style="font-size: 1em; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 38px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: black;">              doPost(req, resp);  </span></li> <li style="font-size: 1em; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 38px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: black;">       }  </span></li> <li style="font-size: 1em; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 38px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: black;">  </span></li> <li style="font-size: 1em; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 38px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: black;">       <span class="keyword" style="color: #7f0055; font-weight: bold;">public</span><span style="color: black;"> </span><span class="keyword" style="color: #7f0055; font-weight: bold;">void</span><span style="color: black;"> doPost(HttpServletRequest req, HttpServletResponse resp) </span><span class="keyword" style="color: #7f0055; font-weight: bold;">throws</span><span style="color: black;"> ServletException, IOException  </span></span></li> <li style="font-size: 1em; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 38px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: black;">       {  </span></li> <li style="font-size: 1em; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 38px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: black;">              resp.getWriter().println(<span class="string" style="color: blue;">"&lt;HTML&gt;&lt;BODY&gt;"</span><span style="color: black;">);  </span></span></li> <li style="font-size: 1em; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 38px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: black;">  </span></li> <li style="font-size: 1em; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 38px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: black;">              resp.getWriter().println(<span class="keyword" style="color: #7f0055; font-weight: bold;">this</span><span style="color: black;"> + </span><span class="string" style="color: blue;">" ==&gt; "</span><span style="color: black;">);  </span></span></li> <li style="font-size: 1em; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 38px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: black;">  </span></li> <li style="font-size: 1em; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 38px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: black;">              resp.getWriter().println(Thread.currentThread() + <span class="string" style="color: blue;">": &lt;br&gt;"</span><span style="color: black;">);  </span></span></li> <li style="font-size: 1em; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 38px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: black;">              <span class="keyword" style="color: #7f0055; font-weight: bold;">for</span><span style="color: black;"> (</span><span class="keyword" style="color: #7f0055; font-weight: bold;">int</span><span style="color: black;"> c = </span><span class="number" style="color: #c00000;">0</span><span style="color: black;">; c &lt; </span><span class="number" style="color: #c00000;">10</span><span style="color: black;">; c++)  </span></span></li> <li style="font-size: 1em; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 38px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: black;">              {  </span></li> <li style="font-size: 1em; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 38px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: black;">                     resp.getWriter().println(<span class="string" style="color: blue;">"Counter = "</span><span style="color: black;"> + counter + </span><span class="string" style="color: blue;">"&lt;BR&gt;"</span><span style="color: black;">);  </span></span></li> <li style="font-size: 1em; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 38px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: black;">                     <span class="keyword" style="color: #7f0055; font-weight: bold;">try</span><span style="color: black;">  </span></span></li> <li style="font-size: 1em; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 38px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: black;">                     {  </span></li> <li style="font-size: 1em; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 38px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: black;">                            Thread.sleep((<span class="keyword" style="color: #7f0055; font-weight: bold;">long</span><span style="color: black;">) Math.random() * </span><span class="number" style="color: #c00000;">1000</span><span style="color: black;">);  </span></span></li> <li style="font-size: 1em; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 38px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: black;">                            counter++;  </span></li> <li style="font-size: 1em; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 38px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: black;">                     }  </span></li> <li style="font-size: 1em; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 38px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: black;">                     <span class="keyword" style="color: #7f0055; font-weight: bold;">catch</span><span style="color: black;"> (InterruptedException exc)  </span></span></li> <li style="font-size: 1em; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 38px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: black;">                     {  </span></li> <li style="font-size: 1em; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 38px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: black;">                     }  </span></li> <li style="font-size: 1em; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 38px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: black;">              }  </span></li> <li style="font-size: 1em; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 38px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: black;">              resp.getWriter().println(<span class="string" style="color: blue;">"&lt;/BODY&gt;&lt;/HTML&gt;"</span><span style="color: black;">);  </span></span></li> <li style="font-size: 1em; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 38px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: black;">       }  </span></li> <li style="font-size: 1em; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 38px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: black;">}  </span></li> </ol> </div> <p> <br><br>然后,我们通过一个html页面向该servlet发出三次请求: <br></p> <div class="dp-highlighter" style="font-family: Monaco, 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', Consolas, 'Courier New', monospace; font-size: 12px; background-color: transparent; width: 694px; margin-left: 9px; padding: 1px;"> <div class="bar"> <div class="tools" style="text-align: left; color: black; font-weight: bold; padding: 3px; margin: 0px;">Java代码  <object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0" width="14" height="15"> <param name="src"> <embed type="application/x-shockwave-flash" width="14" height="15" src="http://zwchen.iteye.com/javascripts/syntaxhighlighter/clipboard_new.swf"></embed></object>  <a style="color: #108ac6; text-decoration: underline;" title="收藏这段代码" href="http://zwchen.iteye.com/blog/91088"><img class="star" style="border-color: initial;" src="http://zwchen.iteye.com/images/icon_star.png" alt="收藏代码"></a> </div> </div> <ol class="dp-j" style="font-size: 1em; line-height: 1.4em; margin-top: 0px; margin-right: 0px; margin-bottom: 1px; margin-left: 0px; padding-top: 2px; padding-right: 0px; padding-bottom: 2px; padding-left: 0px; background-color: #ffffff; color: #2b91af; border: 1px solid #d1d7dc;"> <li style="font-size: 1em; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 38px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: black;"><span style="color: black;">&lt;HTML&gt;  </span></span></li> <li style="font-size: 1em; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 38px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: black;">  </span></li> <li style="font-size: 1em; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 38px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: black;">&lt;BODY&gt;  </span></li> <li style="font-size: 1em; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 38px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: black;">  </span></li> <li style="font-size: 1em; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 38px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: black;">&lt;TABLE&gt;  </span></li> <li style="font-size: 1em; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 38px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: black;">    &lt;TR&gt;  </span></li> <li style="font-size: 1em; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 38px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: black;">        &lt;TD&gt;&lt;IFRAME src=<span class="string" style="color: blue;">"./SimpleServlet"</span><span style="color: black;"> name=</span><span class="string" style="color: blue;">"servlet1"</span><span style="color: black;"> height=</span><span class="string" style="color: blue;">"200%"</span><span style="color: black;">&gt; &lt;/IFRAME&gt;&lt;/TD&gt;  </span></span></li> <li style="font-size: 1em; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 38px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: black;">    &lt;/TR&gt;  </span></li> <li style="font-size: 1em; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 38px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: black;">    &lt;TR&gt;  </span></li> <li style="font-size: 1em; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 38px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: black;">        &lt;TD&gt;&lt;IFRAME src=<span class="string" style="color: blue;">"./SimpleServlet"</span><span style="color: black;"> name=</span><span class="string" style="color: blue;">"servlet2"</span><span style="color: black;"> height=</span><span class="string" style="color: blue;">"200%"</span><span style="color: black;">&gt; &lt;/IFRAME&gt;&lt;/TD&gt;  </span></span></li> <li style="font-size: 1em; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 38px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: black;">    &lt;/TR&gt;  </span></li> <li style="font-size: 1em; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 38px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: black;">    &lt;TR&gt;  </span></li> <li style="font-size: 1em; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 38px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: black;">        &lt;TD&gt;&lt;IFRAME src=<span class="string" style="color: blue;">"./SimpleServlet"</span><span style="color: black;"> name=</span><span class="string" style="color: blue;">"servlet3"</span><span style="color: black;"> height=</span><span class="string" style="color: blue;">"200%"</span><span style="color: black;">&gt; &lt;/IFRAME&gt;&lt;/TD&gt;  </span></span></li> <li style="font-size: 1em; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 38px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: black;">    &lt;/TR&gt;  </span></li> <li style="font-size: 1em; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 38px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: black;">&lt;/TABLE&gt;  </span></li> <li style="font-size: 1em; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 38px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: black;">&lt;/BODY&gt;  </span></li> <li style="font-size: 1em; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 38px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: black;">&lt;/HTML&gt;  </span></li> </ol> </div> <p> <br><br><br><br>刷新页面几次后,产生的结果为: <br><br>com.zwchen.servlet.SimpleServlet@11e1bbf ==&gt; Thread[http-8081-Processor23,5,main]: <br>Counter = 60 <br>Counter = 61 <br>Counter = 62 <br>Counter = 65 <br>Counter = 68 <br>Counter = 71 <br>Counter = 74 <br>Counter = 77 <br>Counter = 80 <br>Counter = 83 <br><br><br><br>com.zwchen.servlet.SimpleServlet@11e1bbf ==&gt; Thread[http-8081-Processor22,5,main]: <br>Counter = 61 <br>Counter = 63 <br>Counter = 66 <br>Counter = 69 <br>Counter = 72 <br>Counter = 75 <br>Counter = 78 <br>Counter = 81 <br>Counter = 84 <br>Counter = 87 <br><br><br><br>com.zwchen.servlet.SimpleServlet@11e1bbf ==&gt; Thread[http-8081-Processor24,5,main]: <br>Counter = 61 <br>Counter = 64 <br>Counter = 67 <br>Counter = 70 <br>Counter = 73 <br>Counter = 76 <br>Counter = 79 <br>Counter = 82 <br>Counter = 85 <br>Counter = 88 <br><br>我们会发现三点: <br><br>servlet只产生了一个Servlet对象,因为输出this时,其hashcode都一样, <br><br>servlet在不同的线程(线程池)中运行,如http-8081-Processor22,http-8081-Processor23 <br><br>Count被这三个doGet方法共享,并且并行修改。 <br><br><br><br>上面的结果,违反了线程安全的两个方面。 <br><br>那么,我们怎样保证按照我们期望的结果运行呢?首先,我想保证产生的count都是顺序执行的。 <br><br>我们将Servlet代码重构如下: <br><br><br></p> <div class="dp-highlighter" style="font-family: Monaco, 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', Consolas, 'Courier New', monospace; font-size: 12px; background-color: transparent; width: 694px; margin-left: 9px; padding: 1px;"> <div class="bar"> <div class="tools" style="text-align: left; color: black; font-weight: bold; padding: 3px; margin: 0px;">Java代码  <object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0" width="14" height="15"> <param name="src"> <embed type="application/x-shockwave-flash" width="14" height="15" src="http://zwchen.iteye.com/javascripts/syntaxhighlighter/clipboard_new.swf"></embed></object>  <a style="color: #108ac6; text-decoration: underline;" title="收藏这段代码" href="http://zwchen.iteye.com/blog/91088"><img class="star" style="border-color: initial;" src="http://zwchen.iteye.com/images/icon_star.png" alt="收藏代码"></a> </div> </div> <ol class="dp-j" style="font-size: 1em; line-height: 1.4em; margin-top: 0px; margin-right: 0px; margin-bottom: 1px; margin-left: 0px; padding-top: 2px; padding-right: 0px; padding-bottom: 2px; padding-left: 0px; background-color: #ffffff; color: #2b91af; border: 1px solid #d1d7dc;"> <li style="font-size: 1em; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 38px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: black;"><span class="keyword" style="color: #7f0055; font-weight: bold;">public</span><span style="color: black;"> </span><span class="keyword" style="color: #7f0055; font-weight: bold;">class</span><span style="color: black;"> SimpleServlet </span><span class="keyword" style="color: #7f0055; font-weight: bold;">extends</span><span style="color: black;"> HttpServlet  </span></span></li> <li style="font-size: 1em; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 38px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: black;">  </span></li> <li style="font-size: 1em; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 38px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: black;">{  </span></li> <li style="font-size: 1em; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 38px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: black;">  </span></li> <li style="font-size: 1em; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 38px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: black;">  <span class="comment" style="color: #008200;">//A variable that is NOT thread-safe!</span><span style="color: black;">  </span></span></li> <li style="font-size: 1em; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 38px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: black;">  </span></li> <li style="font-size: 1em; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 38px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: black;">  <span class="keyword" style="color: #7f0055; font-weight: bold;">private</span><span style="color: black;"> </span><span class="keyword" style="color: #7f0055; font-weight: bold;">int</span><span style="color: black;"> counter = </span><span class="number" style="color: #c00000;">0</span><span style="color: black;">;  </span></span></li> <li style="font-size: 1em; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 38px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: black;">  </span></li> <li style="font-size: 1em; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 38px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: black;">  <span class="keyword" style="color: #7f0055; font-weight: bold;">private</span><span style="color: black;"> String mutex = </span><span class="string" style="color: blue;">""</span><span style="color: black;">;  </span></span></li> <li style="font-size: 1em; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 38px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: black;">  </span></li> <li style="font-size: 1em; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 38px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: black;">   </span></li> <li style="font-size: 1em; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 38px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: black;">  </span></li> <li style="font-size: 1em; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 38px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: black;">  <span class="keyword" style="color: #7f0055; font-weight: bold;">public</span><span style="color: black;"> </span><span class="keyword" style="color: #7f0055; font-weight: bold;">void</span><span style="color: black;"> doGet(HttpServletRequest req, HttpServletResponse resp)  </span></span></li> <li style="font-size: 1em; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 38px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: black;">  </span></li> <li style="font-size: 1em; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 38px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: black;">    <span class="keyword" style="color: #7f0055; font-weight: bold;">throws</span><span style="color: black;"> ServletException, IOException  </span></span></li> <li style="font-size: 1em; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 38px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: black;">{  </span></li> <li style="font-size: 1em; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 38px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: black;">  </span></li> <li style="font-size: 1em; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 38px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: black;">    doPost(req, resp);  </span></li> <li style="font-size: 1em; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 38px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: black;">  </span></li> <li style="font-size: 1em; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 38px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: black;">  }  </span></li> <li style="font-size: 1em; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 38px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: black;">  </span></li> <li style="font-size: 1em; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 38px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: black;">  <span class="keyword" style="color: #7f0055; font-weight: bold;">public</span><span style="color: black;"> </span><span class="keyword" style="color: #7f0055; font-weight: bold;">void</span><span style="color: black;"> doPost(HttpServletRequest req, HttpServletResponse resp)  </span></span></li> <li style="font-size: 1em; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 38px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: black;">  </span></li> <li style="font-size: 1em; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 38px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: black;">    <span class="keyword" style="color: #7f0055; font-weight: bold;">throws</span><span style="color: black;"> ServletException, IOException  </span></span></li> <li style="font-size: 1em; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 38px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: black;">  </span></li> <li style="font-size: 1em; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 38px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: black;">  {  </span></li> <li style="font-size: 1em; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 38px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: black;">  </span></li> <li style="font-size: 1em; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 38px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: black;">    resp.getWriter().println(<span class="string" style="color: blue;">"&lt;HTML&gt;&lt;BODY&gt;"</span><span style="color: black;">);  </span></span></li> <li style="font-size: 1em; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 38px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: black;">  </span></li> <li style="font-size: 1em; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 38px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: black;">    resp.getWriter().println(<span class="keyword" style="color: #7f0055; font-weight: bold;">this</span><span style="color: black;"> + </span><span class="string" style="color: blue;">": &lt;br&gt;"</span><span style="color: black;">);  </span></span></li> <li style="font-size: 1em; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 38px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: black;">  </span></li> <li style="font-size: 1em; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 38px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: black;">    <span class="keyword" style="color: #7f0055; font-weight: bold;">synchronized</span><span style="color: black;"> (mutex)  </span></span></li> <li style="font-size: 1em; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 38px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: black;">  </span></li> <li style="font-size: 1em; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 38px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: black;">    {      </span></li> <li style="font-size: 1em; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 38px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: black;">      <span class="keyword" style="color: #7f0055; font-weight: bold;">for</span><span style="color: black;"> (</span><span class="keyword" style="color: #7f0055; font-weight: bold;">int</span><span style="color: black;"> c = </span><span class="number" style="color: #c00000;">0</span><span style="color: black;">; c &lt; </span><span class="number" style="color: #c00000;">10</span><span style="color: black;">; c++)  </span></span></li> <li style="font-size: 1em; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 38px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: black;">      {  </span></li> <li style="font-size: 1em; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 38px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: black;">        resp.getWriter().println(<span class="string" style="color: blue;">"Counter = "</span><span style="color: black;"> + counter + </span><span class="string" style="color: blue;">"&lt;BR&gt;"</span><span style="color: black;">);  </span></span></li> <li style="font-size: 1em; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 38px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: black;">        <span class="keyword" style="color: #7f0055; font-weight: bold;">try</span><span style="color: black;">  </span></span></li> <li style="font-size: 1em; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 38px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: black;">          {  </span></li> <li style="font-size: 1em; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 38px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: black;">  </span></li> <li style="font-size: 1em; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 38px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: black;">          Thread.sleep((<span class="keyword" style="color: #7f0055; font-weight: bold;">long</span><span style="color: black;">) Math.random() * </span><span class="number" style="color: #c00000;">1000</span><span style="color: black;">);  </span></span></li> <li style="font-size: 1em; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 38px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: black;">          counter++;  </span></li> <li style="font-size: 1em; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 38px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: black;">        }  </span></li> <li style="font-size: 1em; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 38px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: black;">        <span class="keyword" style="color: #7f0055; font-weight: bold;">catch</span><span style="color: black;"> (InterruptedException exc) { }  </span></span></li> <li style="font-size: 1em; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 38px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: black;">      }  </span></li> <li style="font-size: 1em; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 38px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: black;">    }  </span></li> <li style="font-size: 1em; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 38px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: black;">    resp.getWriter().println(<span class="string" style="color: blue;">"&lt;/BODY&gt;&lt;/HTML&gt;"</span><span style="color: black;">);  </span></span></li> <li style="font-size: 1em; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 38px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: black;">  }  </span></li> <li style="font-size: 1em; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 38px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: black;">  </span></li> <li style="font-size: 1em; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 38px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: black;">}  </span></li> </ol> </div> <p> <br><br><br>我们的输出结果为: <br><br>com.zwchen.servlet.SimpleServlet@109da93: <br>Counter = 0 <br>Counter = 1 <br>Counter = 2 <br>Counter = 3 <br>Counter = 4 <br>Counter = 5 <br>Counter = 6 <br>Counter = 7 <br>Counter = 8 <br>Counter = 9 <br><br><br>com.zwchen.servlet.SimpleServlet@109da93: <br>Counter = 10 <br>Counter = 11 <br>Counter = 12 <br>Counter = 13 <br>Counter = 14 <br>Counter = 15 <br>Counter = 16 <br>Counter = 17 <br>Counter = 18 <br>Counter = 19 <br><br>com.zwchen.servlet.SimpleServlet@109da93: <br>Counter = 20 <br>Counter = 21 <br>Counter = 22 <br>Counter = 23 <br>Counter = 24 <br>Counter = 25 <br>Counter = 26 <br>Counter = 27 <br>Counter = 28 <br>Counter = 29 <br><br><br>这符合了我们的要求,输出都是按顺序的,这正式synchronized的含义。 <br><br>附带说一下,我现在synchronized的是一个字符串变量mutex,不是this对象,这主要是从performance和Scalability考虑。Synchronized用在this对象上,会带来严重的可伸缩性的问题(Scalability),所有的并发请求都要排队!</p> <p> </p> <p> </p> <p> </p> <p> </p> <p> </p>
Apache Tomcat/6.0.18 - Error report
各们前辈 你们 知道 : message is is is:<html><head><title>Apache Tomcat/6.0.18 - Error report</title><style><!--H1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} H2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} H3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} BODY {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} B {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} P {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;}A {color : black;}A.name {color : black;}HR {color : #525D76;}--></style> </head><body><h1>HTTP Status 404 - Servlet XiangQi is not available</h1><HR size="1" noshade="noshade"><p><b>type</b> Status report</p><p><b>message</b> <u>Servlet XiangQi is not available</u></p><p><b>description</b> <u>The requested resource (Servlet XiangQi is not available) is not available.</u></p><HR size="1" noshade="noshade"><h3>Apache Tomcat/6.0.18</h3></body></html> 这个错误是怎么引起的吗?? 我在做window.setInterval()定时刷新 调用servlet 的时候 ,浏览器弹出 的错误!; 是不是出现阻塞啊!
如何设置 WebView 内容居中
我想在WebView中加载一些HTML 内容,但是它总是出现在WebView的左上角。 我也使用了stylesheet,在stylesheet中添加了 center related tages,但是也没有居中,别的tags在stylesheet 中可以正常运行。 如何把 WebView的内容设置横向居中或竖向居中? HTML代码: <html><head> <style type=\"text/css\"> @font-face { font-family: MyCustomFont; src:url(\"file:///android_asset/fonts/MyriadPro-Regular.otf\") } body { font-family: MyCustomFont; font-size:14; text-align: center;vertical-align:middle;line-height: normal;} </style> </head><body> Hello World </body></html>
html邮件模板如何循环变量数组
下边是原模板,这个时候数组是固定长度(3)的date,但是我现在想扫表,发每天的数据,所以得到的是一个变量数组长度i不确定date[i],如何在html模板中做循环,求大神在html上写下,谢谢 ``` <?xml version="1.0" encoding="UTF-8"?> <xml-body> <html> <head> </head> <body link="blue" vlink="purple" style="tab-interval:21.0pt;text-justify-trim: punctuation"> <div style='layout-grid:21.15pt'> <p> <span style='font-family:宋体;mso-ascii-font-family:Cambria; mso-ascii-theme-font:minor-latin;mso-fareast-font-family:宋体;mso-fareast-theme-font: minor-fareast;mso-hansi-font-family:Cambria;mso-hansi-theme-font:minor-latin'>亲爱的{0},您好!</span> </p> <p> <span> <span style='mso-tab-count:1'> </span> </span> <span style='font-family:宋体;mso-ascii-font-family:Cambria; mso-ascii-theme-font:minor-latin;mso-fareast-font-family:宋体;mso-fareast-theme-font: minor-fareast;mso-hansi-font-family:Cambria;mso-hansi-theme-font:minor-latin'>您正在绑定安全邮箱,验证码:{1},请在{2}分钟内完成输入。</span> </p> <p> <span> <span style='mso-tab-count:1'> </span> </span> <span style='font-family:宋体;mso-ascii-font-family:Cambria;mso-ascii-theme-font:minor-latin; mso-fareast-font-family:宋体;mso-fareast-theme-font:minor-fareast;mso-hansi-font-family: Cambria;mso-hansi-theme-font:minor-latin'>为了您的信息安全,切勿将验证码透露于他人。</span> </p> <p> <span> <span style='mso-tab-count:1'> </span> </span> <span style='font-family:宋体;mso-ascii-font-family:Cambria;mso-ascii-theme-font:minor-latin; mso-fareast-font-family:宋体;mso-fareast-theme-font:minor-fareast;mso-hansi-font-family: Cambria;mso-hansi-theme-font:minor-latin'>注意:如非本人操作,请及时登录并修改密码以保证账户安全。</span> </p> </div> </body> </html> </xml-body> ```
div自适应字体 用em单位
要实现一个这个功能。一个DIV里面的文字随着DIV框框变化而自适应字体大小,比如 ``` <style> .body{font-size:62.5%} .div{width:100%; height:20%} .span{font-size:3.2em;} </style> <div><span>字体怎么随DIV大小变化而变化</span> </div> ``` 当我分辨率改变的时候 div大小也变化 怎么实现字体跟着变化。 这个用CSS3 的 VW VH可以轻松实现 但是兼容不好。来个讨论队长
相见恨晚的超实用网站
搞学习 知乎:www.zhihu.com 简答题:http://www.jiandati.com/ 网易公开课:https://open.163.com/ted/ 网易云课堂:https://study.163.com/ 中国大学MOOC:www.icourse163.org 网易云课堂:study.163.com 哔哩哔哩弹幕网:www.bilibili.com 我要自学网:www.51zxw
爬虫福利二 之 妹子图网MM批量下载
爬虫福利一:27报网MM批量下载    点击 看了本文,相信大家对爬虫一定会产生强烈的兴趣,激励自己去学习爬虫,在这里提前祝:大家学有所成! 目标网站:妹子图网 环境:Python3.x 相关第三方模块:requests、beautifulsoup4 Re:各位在测试时只需要将代码里的变量 path 指定为你当前系统要保存的路径,使用 python xxx.py 或IDE运行即可。
字节跳动视频编解码面经
引言 本文主要是记录一下面试字节跳动的经历。 三四月份投了字节跳动的实习(图形图像岗位),然后hr打电话过来问了一下会不会opengl,c++,shador,当时只会一点c++,其他两个都不会,也就直接被拒了。 七月初内推了字节跳动的提前批,因为内推没有具体的岗位,hr又打电话问要不要考虑一下图形图像岗,我说实习投过这个岗位不合适,不会opengl和shador,然后hr就说秋招更看重基础。我当时
开源一个功能完整的SpringBoot项目框架
福利来了,给大家带来一个福利。 最近想了解一下有关Spring Boot的开源项目,看了很多开源的框架,大多是一些demo或者是一个未成形的项目,基本功能都不完整,尤其是用户权限和菜单方面几乎没有完整的。 想到我之前做的框架,里面通用模块有:用户模块,权限模块,菜单模块,功能模块也齐全了,每一个功能都是完整的。 打算把这个框架分享出来,供大家使用和学习。 为什么用框架? 框架可以学习整体
源码阅读(19):Java中主要的Map结构——HashMap容器(下1)
(接上文《源码阅读(18):Java中主要的Map结构——HashMap容器(中)》) 3.4.4、HashMap添加K-V键值对(红黑树方式) 上文我们介绍了在HashMap中table数组的某个索引位上,基于单向链表添加新的K-V键值对对象(HashMap.Node&lt;K, V&gt;类的实例),但是我们同时知道在某些的场景下,HashMap中table数据的某个索引位上,数据是按照红黑树
c++制作的植物大战僵尸,开源,一代二代结合游戏
    此游戏全部由本人自己制作完成。游戏大部分的素材来源于原版游戏素材,少部分搜集于网络,以及自己制作。 此游戏为同人游戏而且仅供学习交流使用,任何人未经授权,不得对本游戏进行更改、盗用等,否则后果自负。 目前有六种僵尸和六种植物,植物和僵尸的动画都是本人做的。qq:2117610943 开源代码下载 提取码:3vzm 点击下载--&gt; 11月28日 新增四种植物 统一植物画风,全部修
Java学习的正确打开方式
在博主认为,对于入门级学习java的最佳学习方法莫过于视频+博客+书籍+总结,前三者博主将淋漓尽致地挥毫于这篇博客文章中,至于总结在于个人,实际上越到后面你会发现学习的最好方式就是阅读参考官方文档其次就是国内的书籍,博客次之,这又是一个层次了,这里暂时不提后面再谈。博主将为各位入门java保驾护航,各位只管冲鸭!!!上天是公平的,只要不辜负时间,时间自然不会辜负你。 何谓学习?博主所理解的学习,它
程序员必须掌握的核心算法有哪些?
由于我之前一直强调数据结构以及算法学习的重要性,所以就有一些读者经常问我,数据结构与算法应该要学习到哪个程度呢?,说实话,这个问题我不知道要怎么回答你,主要取决于你想学习到哪些程度,不过针对这个问题,我稍微总结一下我学过的算法知识点,以及我觉得值得学习的算法。这些算法与数据结构的学习大多数是零散的,并没有一本把他们全部覆盖的书籍。下面是我觉得值得学习的一些算法以及数据结构,当然,我也会整理一些看过
Python——画一棵漂亮的樱花树(不同种樱花+玫瑰+圣诞树喔)
最近翻到一篇知乎,上面有不少用Python(大多是turtle库)绘制的树图,感觉很漂亮,我整理了一下,挑了一些我觉得不错的代码分享给大家(这些我都测试过,确实可以生成喔~) one 樱花树 动态生成樱花 效果图(这个是动态的): 实现代码 import turtle as T import random import time # 画樱花的躯干(60,t) def Tree(branch
linux系列之常用运维命令整理笔录
本博客记录工作中需要的linux运维命令,大学时候开始接触linux,会一些基本操作,可是都没有整理起来,加上是做开发,不做运维,有些命令忘记了,所以现在整理成博客,当然vi,文件操作等就不介绍了,慢慢积累一些其它拓展的命令,博客不定时更新 顺便拉下票,我在参加csdn博客之星竞选,欢迎投票支持,每个QQ或者微信每天都可以投5票,扫二维码即可,http://m234140.nofollow.ax.
Python 基础(一):入门必备知识
目录1 标识符2 关键字3 引号4 编码5 输入输出6 缩进7 多行8 注释9 数据类型10 运算符10.1 常用运算符10.2 运算符优先级 1 标识符 标识符是编程时使用的名字,用于给变量、函数、语句块等命名,Python 中标识符由字母、数字、下划线组成,不能以数字开头,区分大小写。 以下划线开头的标识符有特殊含义,单下划线开头的标识符,如:_xxx ,表示不能直接访问的类属性,需通过类提供
深度学习图像算法在内容安全领域的应用
互联网给人们生活带来便利的同时也隐含了大量不良信息,防范互联网平台有害内容传播引起了多方面的高度关注。本次演讲从技术层面分享网易易盾在内容安全领域的算法实践经验,包括深度学习图
程序员接私活怎样防止做完了不给钱?
首先跟大家说明一点,我们做 IT 类的外包开发,是非标品开发,所以很有可能在开发过程中会有这样那样的需求修改,而这种需求修改很容易造成扯皮,进而影响到费用支付,甚至出现做完了项目收不到钱的情况。 那么,怎么保证自己的薪酬安全呢? 我们在开工前,一定要做好一些证据方面的准备(也就是“讨薪”的理论依据),这其中最重要的就是需求文档和验收标准。一定要让需求方提供这两个文档资料作为开发的基础。之后开发
网页实现一个简单的音乐播放器(大佬别看。(⊙﹏⊙))
今天闲着无事,就想写点东西。然后听了下歌,就打算写个播放器。 于是乎用h5 audio的加上js简单的播放器完工了。 欢迎 改进 留言。 演示地点跳到演示地点 html代码如下`&lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; &lt;title&gt;music&lt;/title&gt; &lt;meta charset="utf-8"&gt
Python十大装B语法
Python 是一种代表简单思想的语言,其语法相对简单,很容易上手。不过,如果就此小视 Python 语法的精妙和深邃,那就大错特错了。本文精心筛选了最能展现 Python 语法之精妙的十个知识点,并附上详细的实例代码。如能在实战中融会贯通、灵活使用,必将使代码更为精炼、高效,同时也会极大提升代码B格,使之看上去更老练,读起来更优雅。 1. for - else 什么?不是 if 和 else 才
数据库优化 - SQL优化
前面一篇文章从实例的角度进行数据库优化,通过配置一些参数让数据库性能达到最优。但是一些“不好”的SQL也会导致数据库查询变慢,影响业务流程。本文从SQL角度进行数据库优化,提升SQL运行效率。 判断问题SQL 判断SQL是否有问题时可以通过两个表象进行判断: 系统级别表象 CPU消耗严重 IO等待严重 页面响应时间过长
2019年11月中国大陆编程语言排行榜
2019年11月2日,我统计了某招聘网站,获得有效程序员招聘数据9万条。针对招聘信息,提取编程语言关键字,并统计如下: 编程语言比例 rank pl_ percentage 1 java 33.62% 2 c/c++ 16.42% 3 c_sharp 12.82% 4 javascript 12.31% 5 python 7.93% 6 go 7.25% 7
通俗易懂地给女朋友讲:线程池的内部原理
餐厅的约会 餐盘在灯光的照耀下格外晶莹洁白,女朋友拿起红酒杯轻轻地抿了一小口,对我说:“经常听你说线程池,到底线程池到底是个什么原理?”我楞了一下,心里想女朋友今天是怎么了,怎么突然问出这么专业的问题,但做为一个专业人士在女朋友面前也不能露怯啊,想了一下便说:“我先给你讲讲我前同事老王的故事吧!” 大龄程序员老王 老王是一个已经北漂十多年的程序员,岁数大了,加班加不动了,升迁也无望,于是拿着手里
经典算法(5)杨辉三角
杨辉三角 是经典算法,这篇博客对它的算法思想进行了讲解,并有完整的代码实现。
腾讯算法面试题:64匹马8个跑道需要多少轮才能选出最快的四匹?
昨天,有网友私信我,说去阿里面试,彻底的被打击到了。问了为什么网上大量使用ThreadLocal的源码都会加上private static?他被难住了,因为他从来都没有考虑过这个问题。无独有偶,今天笔者又发现有网友吐槽了一道腾讯的面试题,我们一起来看看。 腾讯算法面试题:64匹马8个跑道需要多少轮才能选出最快的四匹? 在互联网职场论坛,一名程序员发帖求助到。二面腾讯,其中一个算法题:64匹
面试官:你连RESTful都不知道我怎么敢要你?
面试官:了解RESTful吗? 我:听说过。 面试官:那什么是RESTful? 我:就是用起来很规范,挺好的 面试官:是RESTful挺好的,还是自我感觉挺好的 我:都挺好的。 面试官:… 把门关上。 我:… 要干嘛?先关上再说。 面试官:我说出去把门关上。 我:what ?,夺门而去 文章目录01 前言02 RESTful的来源03 RESTful6大原则1. C-S架构2. 无状态3.统一的接
为啥国人偏爱Mybatis,而老外喜欢Hibernate/JPA呢?
关于SQL和ORM的争论,永远都不会终止,我也一直在思考这个问题。昨天又跟群里的小伙伴进行了一番讨论,感触还是有一些,于是就有了今天这篇文。 声明:本文不会下关于Mybatis和JPA两个持久层框架哪个更好这样的结论。只是摆事实,讲道理,所以,请各位看官勿喷。 一、事件起因 关于Mybatis和JPA孰优孰劣的问题,争论已经很多年了。一直也没有结论,毕竟每个人的喜好和习惯是大不相同的。我也看
项目中的if else太多了,该怎么重构?
介绍 最近跟着公司的大佬开发了一款IM系统,类似QQ和微信哈,就是聊天软件。我们有一部分业务逻辑是这样的 if (msgType = "文本") { // dosomething } else if(msgType = "图片") { // doshomething } else if(msgType = "视频") { // doshomething } else { // doshom...
致 Python 初学者
欢迎来到“Python进阶”专栏!来到这里的每一位同学,应该大致上学习了很多 Python 的基础知识,正在努力成长的过程中。在此期间,一定遇到了很多的困惑,对未来的学习方向感到迷茫。我非常理解你们所面临的处境。我从2007年开始接触 python 这门编程语言,从2009年开始单一使用 python 应对所有的开发工作,直至今天。回顾自己的学习过程,也曾经遇到过无数的困难,也曾经迷茫过、困惑过。开办这个专栏,正是为了帮助像我当年一样困惑的 Python 初学者走出困境、快速成长。希望我的经验能真正帮到你
Python 编程实用技巧
Python是一门很灵活的语言,也有很多实用的方法,有时候实现一个功能可以用多种方法实现,我这里总结了一些常用的方法,并会持续更新。
“狗屁不通文章生成器”登顶GitHub热榜,分分钟写出万字形式主义大作
一、垃圾文字生成器介绍 最近在浏览GitHub的时候,发现了这样一个骨骼清奇的雷人项目,而且热度还特别高。 项目中文名:狗屁不通文章生成器 项目英文名:BullshitGenerator 根据作者的介绍,他是偶尔需要一些中文文字用于GUI开发时测试文本渲染,因此开发了这个废话生成器。但由于生成的废话实在是太过富于哲理,所以最近已经被小伙伴们给玩坏了。 他的文风可能是这样的: 你发现,...
程序员:我终于知道post和get的区别
是一个老生常谈的话题,然而随着不断的学习,对于以前的认识有很多误区,所以还是需要不断地总结的,学而时习之,不亦说乎
"狗屁不通文章生成器"登顶GitHub热榜,分分钟写出万字形式主义大作
GitHub 被誉为全球最大的同性交友网站,……,陪伴我们已经走过 10+ 年时间,它托管了大量的软件代码,同时也承载了程序员无尽的欢乐。 万字申请,废话报告,魔幻形式主义大作怎么写?兄dei,狗屁不通文章生成器了解一下。这个富有灵魂的项目名吸引了众人的目光。项目仅仅诞生一周,便冲上了GitHub趋势榜榜首(Js中文网 -前端进阶资源教程)、是榜首哦
推荐几款比较实用的工具,网站
1.盘百度PanDownload 这个云盘工具是免费的,可以进行资源搜索,提速(偶尔会抽风????) 不要去某站买付费的???? PanDownload下载地址 2.BeJSON 这是一款拥有各种在线工具的网站,推荐它的主要原因是网站简洁,功能齐全,广告相比其他广告好太多了 bejson网站 3.二维码美化 这个网站的二维码美化很好看,网站界面也很...
《程序人生》系列-这个程序员只用了20行代码就拿了冠军
你知道的越多,你不知道的越多 点赞再看,养成习惯GitHub上已经开源https://github.com/JavaFamily,有一线大厂面试点脑图,欢迎Star和完善 前言 这一期不算《吊打面试官》系列的,所有没前言我直接开始。 絮叨 本来应该是没有这期的,看过我上期的小伙伴应该是知道的嘛,双十一比较忙嘛,要值班又要去帮忙拍摄年会的视频素材,还得搞个程序员一天的Vlog,还要写BU...
相关热词 c#处理浮点数 c# 生成字母数字随机数 c# 动态曲线 控件 c# oracle 开发 c#选择字体大小的控件 c# usb 批量传输 c#10进制转8进制 c#转base64 c# 科学计算 c#下拉列表获取串口
立即提问