表单里面的元素(如input,select)如果不放在表单里面,能单独提交吗

今天看了单位里面同事们写的页面,他们的input和button都没有写在form里面,请问这样input里面的内容能提交吗

2个回答

图片说明
如图,jquery ajax代码:

function commit(){
var para=$("#input1").val();
$.ajax({
url: "XXXX",
type: "post",
dataType: "json",
data: { method: "XXXX", para:para},
cache: false,
success: function (data) {
}});
}

bulusli3
lhl_lqc 回复工大汪汪: webstorm,专业的js编辑器。
接近 5 年之前 回复
h1580824951
echigh 谢谢了,对了请问你用的啥编辑器啊,很好看
接近 5 年之前 回复

可以,用ajax拼接数据,post回去。

h1580824951
echigh 谢谢回答
接近 5 年之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
其他相关推荐
在HTML中,点击用户注册表单的按钮无法调用js文件中的函数
本人小白,利用netbean8.2制作了一个用户注册的表单,但是却发现点击按钮无法响应事件函数,希望大佬们帮帮忙! **index.html** ``` <html> <head> <style type="text/css">@import url(reg.css);</style> <script language="text/javascript" src="Reg.js"></script> <meta name="keywords" content="keyword1,keyword2,keyword3"> <meta name="content-type" content="textml; charset=GB18030"> <title>用户注册页面</title> </head> <body> <form action=""> <table border="0" align="center" width="600"> <tr><td colspan="3" align="center" height="40" id="title">用户注册</td></tr> <tr><td align="right" id="t">用户名:</td> <td><input type="text" name="username"/></td> <td id="i">*用户名不能为空</td> </tr> <tr><td align="right" id="t">密码:</td> <td><input type="password" name="userpwd"/></td> <td id="i">*不能为空,至少六位</td> </tr> <tr><td align="right" id="t">确认密码:</td> <td><input type="password" name="userpwd1"/></td> <td id="i">*必须与前一次相同</td> </tr> <tr><td align="right" id="t">性别:</td> <td><input type="radio" name="usersex" value="男" checked/>男 <input type="radio" name="usersex" value="女"/>女</td> </tr> <tr><td align="right" id="t">职业:</td> <td> <select> <option value ="总经理">总经理</option> <option value ="经理">经理</option> <option value="秘书">秘书</option> <option value="职员">职员</option> <option value="门卫">门卫</option> </select> </td> <td id="i">*点击选择职业</td> </tr> <tr><td align="right" id="t">电话号码:</td> <td><input type="text" name="userphone"/></td> <td id="i">*至少11位数字</td> </tr> <tr><td align="right" id="t">邮箱地址:</td> <td><input type="text" name="useremail"/></td> <td id="i">*必须包含@符号</td> </tr> <tr><td align="right" id="t">兴趣爱好:</td> <td><input type="checkbox" name="userfav" value="休闲">休闲 <input type="checkbox" name="userfav" value="看书">看书 <input type="checkbox" name="userfav" value="旅游">旅游 <input type="checkbox" name="userfav" value="美食"/>美食</td> </tr> <tr> <td align="right" valign="top">自我简介:</td> <td colspan="2"> <textarea name="userbasicinfo" rows="5" cols="50"></textarea> </td> </tr> <tr> <td colspan="5" align="center" height="40"> <input type="button" value="注册" onclick="Zhuce()"/> </td> </tr> </table> </form> </body> </html> ``` **Reg.js** ``` function Zhuce() { name = document.forms[0].username.value; pwd = document.forms[0].userpwd.value; pwd1 = document.forms[0].userpwd1.value; pho = document.forms[0].userphone.value; mail = document.forms[0].useremail.value; var reg = /^[\w\-\.]+@[a-z0-9]+(\-[a-z0-9]+)?(\.[a-z0-9]+(\-[a-z0-9]+)?)*\.[a-z]{2,4}$/i; if (name.length === 0) alert("用户名不能为空!"); else if (pwd.length === 0 || pwd.length < 6) alert("密码不能为空!,且密码长度必须大于等于6!"); else if (pwd !== pwd1) alert("两次密码不一致!"); else if (pho.length === 0 || pho.length < 11) alert("电话号码不能为空,且至少11位数字!"); else if (!reg.test(mail)) alert("邮箱格式不正确!"); else  document.forms[0].submit(); } ``` 就不知道是哪里出了错,希望大佬帮帮忙!
layui如何隐藏表单上面的三个按钮(筛选,导出excel,打印)
![图片说明](https://img-ask.csdn.net/upload/202002/11/1581428152_503071.png) JSP代码 ``` %> <!DOCTYPE HTML> <html> <style> .layui-input { width: 120px; height: 25px; } .layui-form-select { width: 120px; height: 25px; } </style> </head> <body> <input type="hidden" id="orgId" value="${orgId}"> <input type="hidden" id="bool" value="${bool}"> <input type="hidden" id="currentYear" value="${year}"> <div class="layui-form" style="padding: 5px 2px 5px 0px;background-color: #D4D4D4;margin-top: 0px;margin-bottom: -10px"> <div class="layui-form-item" style="margin-bottom: 0px"> <div class="layui-inline">年份: </div> <div class="layui-inline"> <input class="layui-input" name="year" id="year" autocomplete="off" style="height: 25px;width: 80px"> </div> <div class="layui-inline">调度员角色: </div> <div class="layui-inline"> <select id="dispatchRole" name="dispatchRole" xm-select="dispatchRole" xm-select-create="" xm-select-skin="normal" xm-select-search="" xm-select-max="30"> <option value="">所有</option> <option value="1">操作人</option> <option value="2">审核人</option> <option value="3">值班负责人</option> </select> </div> <div class="layui-inline"> <button class="layui-btn layui-btn-xs" data-type="reload" id="search">搜索</button> <button type="button" lay-submit="" class="layui-btn layui-btn-xs" id="exportWord" name="exportWord"> <i class="layui-icon"></i>导出Word</button> </div> </div> </div> <div id="docx"> <div class="WordSection1"> </div> </div> <script type="text/html" id="statisticsTool"> <div class="layui-btn-container" id="layerDemo"> <button data-method="offset" data-type="auto" class="layui-btn layui-btn-xs" lay-event="addUser" id="dddd">配置人员 </button> </div> </script> <table id="statisticsTable" lay-filter="statisticsTable" class="layui-hide" style="width: 500px;padding-top: -20px"></table> </body> </html> ``` 我要把layui自带的三个按钮隐藏,帮配置人员移到上面一排
为什么mysql数据库的图片不显示? add和调用函数已写好,我感觉是if action=show 后面代码的问题 但不清楚请指出!
功能:php实现将图片存入mysql并取出预览: 数据库结构: ![图片说明](https://img-ask.csdn.net/upload/202003/15/1584244372_389746.png) 代码 ``` <?php // 连接数据库 //echo realpath('..');//获得上级目录 两个点 获得当前目录 一个点 include(realpath('..').'\controller\sqlConnect.php'); // 判断action $action = isset($_REQUEST['action'])? $_REQUEST['action'] : ''; $tableName="photo"; // 上传图片 if($action=='add'){ //防止出现‘ “” 等字符,对其进行/ 转义 //$image = mysqli_real_escape_string($link,file_get_contents($_FILES['photo']['tmp_name'])); $image=base64_encode(file_get_contents($_FILES['photo']['tmp_name'])); // $_FILES['photo']['tmp_name'] 文件存储路径名 file_get_contents: 由路径获得文件内容 //$_FILES['photo']['type'] 获取文件类别 $type = $_FILES['photo']['type']; //ob_clean(); //echo $image; //echo $type."\n"; $sql = "INSERT INTO photo (userId,photoType,photoBinaryData) VALUES(1,'$type','$image')"; //谨记插入式变量需加引号!!! if(mysqli_query($link,$sql)or die(mysqli_error($link))) { echo "save successfully!"; header('url=addPhoto.php'); } else { echo "insert failed"; echo mysql_error(); exit(); } } elseif($action=='show'){ $photoId = isset($_GET['photoId'])? intval($_GET['photoId']) : 0;//intval:转化为整数 //echo $photoId; //echo $photoId; //console.log($photoId); $sqlstr = "select * from photo where photoId=$photoId"; $query = mysqli_query($link,$sqlstr) or die(mysqli_error($link)); $thread = mysqli_fetch_assoc($query); if($thread){ $photoShow=base64_decode($thread['photoBinaryData']); header('content-type:'.$thread['photoType']); echo $photoShow; exit(); } }else{ // 显示图片列表及上传表单 ?> <!DOCTYPE HTML > <html> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8"> <title> upload image to db demo </title> </head> <body> <form name="form1" method="post" action="addPhoto.php" enctype="multipart/form-data"> <p>图片:<input type="file" name="photo"></p> <p><input type="hidden" name="action" value="add"><input type="submit" name="b1" value="提交"></p> </form> <?php $sqlstr = "select * from photo order by photoId desc"; $query = mysqli_query($link,$sqlstr) or die(mysqli_error($link)); $result = array(); while($thread=mysqli_fetch_assoc($query)){ $result[] = $thread; } foreach($result as $val){ echo '<p><img src="addPhoto.php?action=show&photoId='.$val['photoId'].'&t='.time().'" width="150" height="150"></p>'; echo "<br/>".$val['photoType']; } ?> </body> </html> <?php } ?> ``` 结果: ![图片说明](https://img-ask.csdn.net/upload/202003/15/1584244476_182364.png) 问题:为什么mysql数据库的图片不显示? add和调用函数已写好,我感觉是if action=show 后面代码的问题 但不清楚请指出!
把php表达上传文件转化成libcrul 的curl_formadd实现,代码通过,发币!谢谢朋友们帮帮忙吧,总是对应不上! 有更好的例子也可以!
``` <?php $header_prefix = 'file'; $slots = 6; ?> <html> <head> <title>Test upload</title> </head> <body> <?php if ($_POST){ echo "<h2>Uploaded files:</h2>"; echo "<table border=\"2\" cellpadding=\"2\">"; echo "<tr><td>Name</td><td>Location</td><td>Content type</td><td>MD5</td><td>Size</td><td>Scp Command</td><td>Wget Command</tr>"; for ($i=1;$i<=$slots;$i++){ $key = $header_prefix.$i; if (array_key_exists($key."_name", $_POST) && array_key_exists($key."_path",$_POST)) { $tmp_name = $_POST[$key."_path"]; $name = $_POST[$key."_name"]; $content_type = $_POST[$key."_content_type"]; $md5 = $_POST[$key."_md5"]; $size = $_POST[$key."_size"]; $final_path = "/export/share/upload"; if (copy($tmp_name, "$final_path/$name")) { echo "SUCCESS!"; } else { echo "FAIL!"; } $scp_cmd = "scp team@***:/export/share/upload/$name ."; $wget_cmd = "wget http://***/files/upload/$name"; echo "<tr><td>$name</td><td>$final_path</td><td>$content_type</td><td>$md5</td><td>$size</td><td>$scp_cmd</td><td>$wget_cmd</td>"; } } echo "</table>"; }else{?> <h2>Select files to upload</h2> <form name="upload" method="POST" enctype="multipart/form-data" action="/upload"> <input type="file" name="file1"><br> <input type="file" name="file2"><br> <input type="file" name="file3"><br> <input type="file" name="file4"><br> <input type="file" name="file5"><br> <input type="file" name="file6"><br> <input type="submit" name="submit" value="Upload"> <input type="hidden" name="test" value="value"> </form> <?php } ?> </body> </html> ``` 把以上的PHP动态提交表单的行为,用libcurl 中 curl_formadd 实现,感谢路过的大神伸出智慧之手!需要使用C++完成上面的实现
求问,如何做一个二级联动的下拉表单(select),每点击一下按钮,表单增加一行。
求问,如何做一个二级联动的下拉表单(select),每点击一下按钮,表单增加一行。我现在的问题是,表单增加后,二级联动就没有效果了。 这是html和表单元素代码 <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <script type="text/javascript" src="js/jquery.js"></script> <script type="text/javascript" src="js/tab.js"></script> <script type="text/javascript" src="js/select2.js"></script> <link href="css/select2.css" rel="stylesheet"/> </style> </head> <body> <br> <table class="table" > <thead> <tr> <th>厚度</th> <th>光度</th> <th>外观</th> </tr> </thead> <tbody> <tr id="a"> <td> <div class="demo"> <div id="city_5"> <select class="prov"></select> <select class="city" disabled="disabled"></select> <select class="dist" disabled="disabled"></select> </div> </div> </td> <td><input type="" name=""></td> <td><input type="" name=""></td> </tr> </tbody> </table> <button onclick="fun()">增加一行</button> <button onclick="del()">删除一行</button> <script type="text/javascript" src="jquery.cityselect.js"></script> <script type="text/javascript"> $(function() { $("#city_5").citySelect({ url: {"citylist": [ {"p": "前端课程", "c": [{"n": "HTML5"}, {"n": "CSS3", "a": [{"s": "HTML"}, {"s": "AJAX"}]}, {"n": "JSON"}]}, {"p": "编程语言", "c": [{"n": "C"}, {"n": "C++"}, {"n": "Python"}, {"n": "PHP"}, {"n": "JAVA"}]}, {"p": "数据库", "c": [{"n": "Mysql"}, {"n": "SqlServer"}, {"n": "Oracle"}, {"n": "Mssql"}]}, ]}, prov: "", city: "", dist: "", nodata: "none" }); }); </script> </body> </html> 这是增加一行的代码 var i = 1; $(".td").each(function(){ $(this).html(i++); }) function fun(){ var $td = $("#a").clone(); //增加一行,克隆第一个对象 $(".table").append($td); var i = 1; $(".td").each(function(){ //增加一行后重新更新序号1,2,3...... $(this).html(i++); }) $("table tr:last").find(":input").val(''); //将尾行元素克隆来的保存的值清空 } function del(){ $("table tr:not(:first):not(:first):last").remove(); //移除最后一行,并且保留前两行 } 这是二级联动代码 /* Ajax 三级省市联动 http://code.ciaoca.cn/ 日期:2012-7-18 settings 参数说明 ----- url:省市数据josn文件路径 prov:默认省份 city:默认城市 dist:默认地区(县) nodata:无数据状态 required:必选项 ------------------------------ */ (function($) { $.fn.citySelect = function(settings) { if (this.length < 1) { return; } ; // 默认值 settings = $.extend({ url: "city.min.js", prov: null, city: null, dist: null, nodata: null, required: true }, settings); var box_obj = this; var prov_obj = box_obj.find(".prov"); var city_obj = box_obj.find(".city"); var dist_obj = box_obj.find(".dist"); var prov_val = settings.prov; var city_val = settings.city; var dist_val = settings.dist; var select_prehtml = (settings.required) ? "" : "<option value=''>请选择</option>"; var city_json; // 赋值市级函数 var cityStart = function() { var prov_id = prov_obj.get(0).selectedIndex; if (!settings.required) { prov_id--; } ; city_obj.empty().attr("disabled", true); dist_obj.empty().attr("disabled", true); if (prov_id < 0 || typeof (city_json.citylist[prov_id].c) == "undefined") { if (settings.nodata == "none") { city_obj.css("display", "none"); dist_obj.css("display", "none"); } else if (settings.nodata == "hidden") { city_obj.css("visibility", "hidden"); dist_obj.css("visibility", "hidden"); } ; return; } ; // 遍历赋值市级下拉列表 temp_html = select_prehtml; $.each(city_json.citylist[prov_id].c, function(i, city) { temp_html += "<option value='" + city.n + "'>" + city.n + "</option>"; }); city_obj.html(temp_html).attr("disabled", false).css({"display": "", "visibility": ""}); distStart(); }; // 赋值地区(县)函数 var distStart = function() { var prov_id = prov_obj.get(0).selectedIndex; var city_id = city_obj.get(0).selectedIndex; if (!settings.required) { prov_id--; city_id--; } ; dist_obj.empty().attr("disabled", true); if (prov_id < 0 || city_id < 0 || typeof (city_json.citylist[prov_id].c[city_id].a) == "undefined") { if (settings.nodata == "none") { dist_obj.css("display", "none"); } else if (settings.nodata == "hidden") { dist_obj.css("visibility", "hidden"); } ; return; } ; // 遍历赋值市级下拉列表 temp_html = select_prehtml; $.each(city_json.citylist[prov_id].c[city_id].a, function(i, dist) { temp_html += "<option value='" + dist.s + "'>" + dist.s + "</option>"; }); dist_obj.html(temp_html).attr("disabled", false).css({"display": "", "visibility": ""}); }; var init = function() { // 遍历赋值省份下拉列表 temp_html = select_prehtml; $.each(city_json.citylist, function(i, prov) { temp_html += "<option value='" + prov.p + "'>" + prov.p + "</option>"; }); prov_obj.html(temp_html); // 若有传入省份与市级的值,则选中。(setTimeout为兼容IE6而设置) setTimeout(function() { if (settings.prov != null) { prov_obj.val(settings.prov); cityStart(); setTimeout(function() { if (settings.city != null) { city_obj.val(settings.city); distStart(); setTimeout(function() { if (settings.dist != null) { dist_obj.val(settings.dist); } ; }, 1); } ; }, 1); } ; }, 1); // 选择省份时发生事件 prov_obj.bind("change", function() { cityStart(); }); // 选择市级时发生事件 city_obj.bind("change", function() { distStart(); }); }; // 设置省市json数据 if (typeof (settings.url) == "string") { $.getJSON(settings.url, function(json) { city_json = json; init(); }); } else { city_json = settings.url; init(); } ; }; })(jQuery);
基于springmvc+mybatis的登录表单提交后404
前端填写正确的用户名和密码后,提交登录,浏览器显示404,前端提交的地址是/userlogin,后端对接的/user/userlogin也是对的,浏览器f12里显示请求的确成功传给了后端,但是不知道为什么404。用的是tomcat8.5,java版本1.8,phpstudy最新版,mysql5.7.26。 ## 这是所用到的包: ![图片说明](https://img-ask.csdn.net/upload/202002/01/1580567617_880785.jpg) ## 这是目录结构: ![图片说明](https://img-ask.csdn.net/upload/202002/01/1580567511_223692.jpg) ## 这是web.xml: ```xml <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5"> <display-name>springmvc_test</display-name> <welcome-file-list> <welcome-file>index.html</welcome-file> <welcome-file>index.jsp</welcome-file> </welcome-file-list> <!-- 配置spring监听器 --> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <!-- 加载spring配置文件 --> <context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath*:config/context-config.xml</param-value> </context-param> <!-- 配置前端控制器 --> <servlet> <servlet-name>springmvc</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init-param> <!-- DispatcherServlet在初始化方法里面会读取该初始化参数的值来获得 spring配置文件的位置 ,然后启动spring容器。 --> <param-name>contextConfigLocation</param-name> <param-value>classpath*:config/springmvc-config.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>springmvc</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping> <!-- 配置字符编码 --> <filter> <filter-name>encodingFilter</filter-name> <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class> <init-param> <param-name>encoding</param-name> <param-value>UTF-8</param-value> </init-param> </filter> <filter-mapping> <filter-name>encodingFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> </web-app> ``` ## 这是context-config.xml: ```xml <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"> <!-- 扫描service包下的注解 --> <context:component-scan base-package="com.test.service"></context:component-scan> <!-- 配置数据库 --> <!-- 加载配置文件 --> <!-- <context:property-placeholder location="classpath:jdbc.properties"/> --> <bean id="dateSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"> <property name="driver" value="com.mysql.jdbc.Driver"></property> <property name="url" value="jdbc:mysql://localhost:3306/Eday_Test"></property> <property name="username" value="root"></property> <property name="password" value="123456"></property> </bean> <!-- 配置Sqlsessionfactory并将数据源注入 --> <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> <!-- 引入数据源 --> <property name="dateSource" ref="dateSource"></property> <!-- 载入mybatis配置文件 --> <property name="configLocation" value="classpath:mybatis-config.xml"></property> <!-- 载入配置mapper映射的xml --> <property name="mapperLocations" value="classpath:com/test/mapper/*.xml"></property> </bean> <!-- 配置扫描mapper接口 --> <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"> <property name="basePackge" value="com.test.mapper"></property> <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"></property> </bean> <!-- 配置事务管理器 --> <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <property name="dateSource" ref="dateSource"></property> </bean> <tx:annotation-driven transaction-manager="transactionManager"/> </beans> ``` ## 这是mybatis-config.xml: ```xml <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-config.dtd"> <configuration> <typeAliases> <!-- 配置别名 --> <typeAlias alias="User" type="com.test.pojo.User"/> </typeAliases> </configuration> ``` ## 这是springmvc-config.xml: ```xml <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd"> <!-- 扫描controller包下的注解 --> <context:component-scan base-package="com.test.controller"></context:component-scan> <!-- 开启注解 --> <mvc:annotation-driven></mvc:annotation-driven> <!-- 静态资源访问 --> <mvc:default-servlet-handler/> <!-- 视图解析器 --> <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <!-- 配置试图解析的默认路径,即配置页面的根路径 --> <property name="prefix" value="/"></property> <property name="suffix" value=".jsp"></property> </bean> </beans> ``` ## 这是UserController.java: ```java package com.test.controller; import javax.servlet.http.HttpSession; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Scope; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.servlet.ModelAndView; import com.test.pojo.User; import com.test.service.UserService; //声明控制器 @Controller //设置bean的scope属性为多例(prototype) @Scope("prototype") //设置请求映射,当客户端请求/user时,转到该控制器处理 @RequestMapping("/user") public class UserController { @Autowired private UserService userService; @RequestMapping(value="/userlogin") public ModelAndView login(String user_Name,String user_pwd,ModelAndView mv,HttpSession session){ //调用userService中的login方法处理user实体类对象 User user = userService.login(user_Name,user_pwd); //登录的逻辑判断,判断条件是返回结果不为空 if(user!=null){ //登陆成功,将user对象设置到HttpSession作用范围域中,相当于服务端的cookie,有效时间默认30分钟 //在程序运行期间,在任意页面都可以提取它的值。 session.setAttribute("user",user); //转发到main请求 //登录成功,跳转页面 mv.setViewName("login/login-success"); }else{ //登录失败,向前端传递失败信息 mv.addObject("message","用户名或密码错误,请重新输入!"); //登录失败,跳转到登录页面 mv.setViewName("login"); } return mv; } //跳转到用户注册界面 @RequestMapping(value="/userregister"/*,method=RequestMethod.POST*/) public String register(User user){ String user_Name = user.getUser_Name(); //如果数据库中没有该用户,可以注册,否则跳转页面 if(userService.findByUserName(user_Name)==null){ //添加用户 userService.register(user); //注册成功,跳转到主页面 return "index"; }else{ //注册失败,跳转到错误页面 return "error"; } } } ``` ## 这是UserMapper.java: ```java package com.test.mapper; import org.apache.ibatis.annotations.Param; import com.test.pojo.User; public interface UserMapper { //根据用户名和密码查找,mybatis中有多个参数时,需要使用@Param注解 User findByUserNameAndPassword(@Param("user_Name")String user_Name,@Param("user_Pwd")String user_Pwd); //增加用户 void addUser(User user); //根据用户名查询 User findByUserName(String user_Name); } ``` ## 这是UserMapper.xml: ```xml <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE mapper PUBLIC "//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <mapper namespace="com.tes.mapper.UserMapper"> <!-- 根据用户名和密码查询 --> <select id="findByUserNameAndPasssword" resultType="User"> select * from user where user_Name=#{user_Name} and user_Pwd=#{user_Pwd} </select> <!-- 增加用户 --> <insert id="addUser" parameterType="User"> insert into user (user_Name,user_Pwd,user_Email,user_NickName,user_Birth,user_Phone,user_InvitationCode) values(#{user_Name},#{user_Pwd},#{user_Email},#{user_NickName},#{user_Birth},#{user_Phone},#{user_InvitationCode}) </insert> <!-- 根据用户名查询 --> <select id="findByUserName" resultType="User"> select * from user where user_Name=#{user_Name} </select> </mapper> ``` ## 这是User.java: ```java package com.test.pojo; import java.sql.Timestamp; public class User { private int user_Id; private String user_Name; private int user_Pwd; private String user_Email; private String user_NickName; private Timestamp user_Time; private String user_Birth; private int user_Fans; private int user_Follow; private int user_Score; private String user_HeadImgAddr; private int user_Phone; private String user_InvitationCode; public int getUser_Id() { return user_Id; } public void setUser_Id(int user_Id) { this.user_Id = user_Id; } public String getUser_Name() { return user_Name; } public void setUser_Name(String user_Name) { this.user_Name = user_Name; } public int getUser_Pwd() { return user_Pwd; } public void setUser_Pwd(int user_Pwd) { this.user_Pwd = user_Pwd; } public String getUser_Email() { return user_Email; } public void setUser_Email(String user_Email) { this.user_Email = user_Email; } public String getUser_NickName() { return user_NickName; } public void setUser_NickName(String user_NickName) { this.user_NickName = user_NickName; } public Timestamp getUser_Time() { return user_Time; } public void setUser_Time(Timestamp user_Time) { this.user_Time = user_Time; } public String getUser_Birth() { return user_Birth; } public void setUser_Birth(String user_Birth) { this.user_Birth = user_Birth; } public int getUser_Fans() { return user_Fans; } public void setUser_Fans(int user_Fans) { this.user_Fans = user_Fans; } public int getUser_Follow() { return user_Follow; } public void setUser_Follow(int user_Follow) { this.user_Follow = user_Follow; } public int getUser_Score() { return user_Score; } public void setUser_Score(int user_Score) { this.user_Score = user_Score; } public String getUser_HeadImgAddr() { return user_HeadImgAddr; } public void setUser_HeadImgAddr(String user_HeadImgAddr) { this.user_HeadImgAddr = user_HeadImgAddr; } public int getUser_Phone() { return user_Phone; } public void setUser_Phone(int user_Phone) { this.user_Phone = user_Phone; } public String getUser_InvitationCode() { return user_InvitationCode; } public void setUser_InvitationCode(String user_InvitationCode) { this.user_InvitationCode = user_InvitationCode; } @Override public String toString() { return "User [user_Id=" + user_Id + ", user_Name=" + user_Name + ", user_Pwd=" + user_Pwd + ", user_Email=" + user_Email + ", user_NickName=" + user_NickName + ", user_Time=" + user_Time + ", user_Birth=" + user_Birth + ", user_Fans=" + user_Fans + ", user_Follow=" + user_Follow + ", user_Score=" + user_Score + ", user_HeadImgAddr=" + user_HeadImgAddr + ", user_Phone=" + user_Phone + ", user_InvitationCode=" + user_InvitationCode + "]"; } } ``` ## 这是UserService.java: ```java package com.test.service; import com.test.pojo.User; public interface UserService { //通过用户名及密码核查用户登录 User login(String user_Name,String user_Pwd); //增加用户 void register(User user); //根据用户名查询 User findByUserName(String user); } ``` ## 这是UserServiceImpl.java: ```java package com.test.service.impl; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import com.test.mapper.UserMapper; import com.test.pojo.User; import com.test.service.UserService; @Service @Transactional public class UserServiceImpl implements UserService { //注入UserMapper接口 @Autowired private UserMapper userMapper; //登录,根据用户名和密码进行查询 @Override public User login(String user_Name,String user_Pwd){ return userMapper.findByUserNameAndPassword(user_Name,user_Pwd); } //注册,增加用户 @Override public void register(User user){ userMapper.addUser(user); } //根据用户名查询 @Override public User findByUserName(String user_Name){ return userMapper.findByUserName(user_Name); } } ``` ##这是login.jsp ```jsp <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <link rel="stylesheet" type="text/css" href="../css/login.css" /> <title>登录</title> </head> <body> <!--导航栏--> <nav class="nav"> <ul> <li class="logo"><a href="#">Eday</a></li> <li class="shouye"><a href="../index.jsp" class="neirong">首页</a></li> <li class="fgx">|</li> <li><a href="#" class="neirong">文章列表</a></li> <li class="fgx">|</li> <li><a href="#" class="neirong">留言板</a></li> <li class="fgx">|</li> <li><a href="#" class="neirong">更新日志</a></li> </ul> </nav> <!--登录板块--> <header class="header"> <p class="logintitle"> <b>登录</b> </p> <form action="${pageContext.request.contextPath }/user/userlogin" method="post" class=login-form> <p class= login-username-p> <label for="username" class="login-username-text">用户名:</label> <input type=text name="user_Name" class="login-username-input"> <br><a href="register.jsp" class=login-register>注册</a> </p> <p class="login-psw-p"> <label for="psw" class="login-psw-text">密码:</label> <input type=password name="user_Pwd" class="login-psw-input"> <br><a href="#" class=login-forget>忘记密码</a> </p> <div class=login-button-div> <label for=button></label> <button type=sublim class=login-button>登录</button> </div> </form> </header> </body> </html> ``` ## 这是login-success.jsp: ```jsp <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>登录成功,请等待跳转...</title> <script type="text/javascript"> onload=function(){ setInterval(go, 1000); }; var x=3; //利用了全局变量来执行 function go(){ x--; if(x>0){ document.getElementById("sp").innerHTML=x; //每次设置的x的值都不一样了。 }else{ location.href='../index.jsp'; } } </script> </head> <body> <!--导航栏--> <nav class="nav"> <ul> <li class="logo"><a href="#">Eday</a></li> <li class="shouye"><a href="../index.jsp" class="neirong">首页</a></li> <li class="fgx">|</li> <li><a href="#" class="neirong">文章列表</a></li> <li class="fgx">|</li> <li><a href="#" class="neirong">留言板</a></li> <li class="fgx">|</li> <li><a href="#" class="neirong">更新日志</a></li> </ul> </nav> <header> <div> <p>登录成功!页面将在3秒后自动跳转,请稍等...</p> </div> </header> </body> </html> ``` ## 这是数据库: ![图片说明](https://img-ask.csdn.net/upload/202002/01/1580568589_694404.jpg)
jquery,怎么获取表单元素类型?
``` $("#submit").click(function () { var sumQ = $("#MTform").serializeArray(); var strs = ""; for (i = 0; i < sumQ.length; i++) { if(sumQ[i].value === ""){ //alert($("#"+sumQ[i].name).type); //判断input,select,checkbox类型,在这里用哪个语法获取当前是input还是select呢? ; } } }); ```
开发类似django admin actions功能时,复选框勾选提交后没有反应,代码完全照葫芦挖瓢抄的
<form action="" method="post" onsubmit="return ActionSubmit(this)">{% csrf_token %} <div class="col-lg-2" style="margin-left: 15px"> <select id="action_list" name="action" class="form-control"> <option value="">--------</option> {% for action in model_obj.actions %} <option value="{{ action }}">{{ action }}</option> {% endfor %} </select> </div> <div class="col-lg-1"> <button type="button" class="btn" >Go</button> </div> </form> <thead> <tr> <th style="width: 35px" ><input type="checkbox" onclick="CheckAllToggle(this)"></th> {% for column in model_obj.list_display %} {% built_table_header_column column orderby_key %} {# <th><a href="?o={{ column }}">{{ column }}</a></th>#} {% endfor %} </tr> </thead> <tbody> <tr> {# {% get_query_sets model_obj as query_sets %}#} {% for obj in query_sets %} <tr> <td><input tag="obj_checkbox" type="checkbox" value="{{ obj.id }}"></td> {% built_table_row request obj model_obj %} </tr> {% endfor %} </tr> </tbody> <script> function CheckAllToggle(ele) { console.log($(ele).prop("checked")) if ($(ele).prop("checked")){ $("input[tag='obj_checkbox']").prop("checked", true); } else { $("input[tag='obj_checkbox']").prop("checked", false); } } function ActionSubmit(form_ele) { var selected_ids = []; $("input[tag='obj_checkbox']:checked").each(function () { selected_ids.push($(this).val()); }) var selected_action = $("#action_list").val(); {#console.log(selected_action)#} if (selected_ids.length==0){ alert("No object got selected!"); return } if (!selected_action){ alert("No action got selected!"); return } {# 有action,也选择了checkbox #} // 在form表单里添加一个隐藏的 input,并且带上参数selected_ids var selected_ids_ele = "<input name='selected_ids' type='hidden' value='" + selected_ids.toString() + "' >" $(form_ele).append(selected_ids_ele); return true } </script> ![图片说明](https://img-ask.csdn.net/upload/202002/25/1582565161_766516.png) ``` ```
easyui页面显示,就是在主页面显示另一个页面,那个页面没有完整的显示出来,但是在地址栏上输入那个页面的地址,那个页面就完整的显示,这怎么农
使用easyui做的main.jsp和busCarsManager.jsp 在main.jsp点击车辆管理即busCarsManager.jsp,显示成了这样 如下图 ![图片说明](https://img-ask.csdn.net/upload/202003/04/1583329850_48245.png) 在地址栏输入该页面url地址 ![图片说明](https://img-ask.csdn.net/upload/202003/04/1583329898_132483.png) 怎么弄好?? 以下是main.jsp代码 <title>Basic Form - jQuery EasyUI Demo</title> <link rel="stylesheet" type="text/css" href="easyui/themes/default/easyui.css"> <link rel="stylesheet" type="text/css" href="easyui/themes/icon.css"> <link rel="stylesheet" type="text/css" href="easyui/themes/demo.css"> <script type="text/javascript" src="easyui/jquery.min.js"></script> <script type="text/javascript" src="easyui/jquery.easyui.min.js"></script> <script type="text/javascript"> $(function() { $('#tt').tree({ //点击菜单事件 onClick: function(node){ //如果选项的url为空,null,直接退出,在页面不变 if(node.url==""||node.url==null){ return; } //如果选项卡存在 var flag=$('#tab').tabs('exists',node.text); //存在的条件下,选中,显示其内容 if(flag){ $('#tab').tabs('select',node.text); }else{ $('#tab').tabs('add',{ title: node.text, href:node.url, closable:true }); } } }); }); </script> <title>汽车租赁系统</title> </head> <body class="easyui-layout"> <div data-options="region:'north',split:true" style="height:100px;background: url('images/绿色.jpg')"> <div style="margin-left: 120px;margin-top: 30px;float:left;"> <span style="font-size: 32px;color:orange;font-weight:bold;">汽车租赁系统</span> </div> <div style="float: right ;margin-top: 60px;margin-right: 30px"> <span style="font-size: 18px;color: red;">欢迎admin用户登录</span> <a style="font-size: 18px;color: red;text-decoration: none">注销</a> </div> </div> <div data-options="region:'south',title:'版权信息',split:true" style="height:200px;background: url('images/版权信息.png'); background-repeat: no-repeat;background-color: silver;background-position: center;"></div> <div data-options="region:'east',title:'East',split:true" style="width:200px;"> <div id="date" class="easyui-calendar" style="width:180px;height:200px;"></div> </div> <div data-options="region:'west',title:'West',split:true" style="width:150px;"> <div id="menu" class="easyui-accordion" data-options="fit:true,border:false"> <div title="类别一"> <ul id="tt" class="easyui-tree" url="SysMenusController/findMoreMenus"></ul> </div> <div title="类别二"></div> <div title="类别三"></div> </div> </div> <div data-options="region:'center'" style="background:#eee;"> <div id="tab" class="easyui-tabs" data-options="fit:true"> <div title="默认页"> <img src="images/默认页.jpeg" width="90%" height="90%"> </div> </div> </div> </body> 以下是busCarsManager.jsp代码 <body data-options="fit:true"> <table id="busCarsManger_dg" title="My Cars" class="easyui-datagrid" style="width:600px;height:250px" url="/busCarsController/findAllBusCars" toolbar="#busCarsManger_toolbar" pagination="true" rownumbers="true" fitColumns="true" singleSelect="true"> <thead> <tr> <th field="carnumber" width="50">汽车牌号</th> <th field="lastname" width="50">汽车类型</th> <th field="pice" width="50">汽车价格</th> <th field="description" width="50">汽车描述</th> <th data-options="field:'carimg',formatter:showImage" width="50">汽车图片</th> </tr> </thead> </table> <div id="busCarsManger_toolbar"> <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="newCars()">新增汽车</a> <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-edit" plain="true" onclick="editCars()">修改汽车信息</a> <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="destroyCars()">移除</a> </div> <div id="busCarsManger_dlg" class="easyui-dialog" style="width:500px" data-options="closed:true,modal:true,border:'thin',buttons:'#busCarsManger_dlg-buttons'"> <form id="busCarsManger_fm" method="post" novalidate style="margin:0;padding:20px 50px"> <h3>汽车信息</h3> <div style="margin-bottom:10px"> <input name="carnumber" class="easyui-textbox" required="true" label="汽车牌号:" style="width:100%"> </div> <div style="margin-bottom:10px"> <input name="cartype" class="easyui-textbox" required="true" label="汽车类型:" style="width:100%"> </div> <div style="margin-bottom:10px"> <input name="color" class="easyui-textbox" required="true" label="汽车颜色" style="width:100%"> </div> <div style="margin-bottom:10px"> <input name="price" class="easyui-textbox" required="true" label="汽车价格" style="width:100%"> </div> <div style="margin-bottom:10px"> <input name="rentprice" class="easyui-textbox" required="true" label="汽车租金" style="width:100%"> </div> <div style="margin-bottom:10px"> <input name="deposit" class="easyui-textbox" required="true" label="汽车押金" style="width:100%"> </div> <div style="margin-bottom:10px"> <input name="description" class="easyui-textbox" required="true" label="汽车描述" style="width:100%"> </div> <input type="text" name="carimg" id="carimg"> </form> <form id="fm2" method="post" enctype="multipart/form-data" style="margin:0;padding:20px 50px"> <div style="margin-bottom:10px"> <input name="fil" class="easyui-filebox" label="汽车图片" style="width:70%"> <a href="javascript:void(0)" class="easyui-linkbutton c6" iconCls="icon-ok" onclick="fileUpload()" style="width:100px">上传图片</a> </div> <span id="sp1"></span> </form> </div> <div id="busCarsManger_dlg-buttons"> <a href="javascript:void(0)" class="easyui-linkbutton c6" iconCls="icon-ok" onclick="saveCars()" style="width:90px">Save</a> <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:$('#dlg').dialog('close')" style="width:90px">Cancel</a> </div> <script type="text/javascript"> //全局参数地址 var url; //删除车辆系信息操作 function destroyCars(){ //当表格信息被选中 var row= $('#busCarsManger_dg').datagrid('getSelected'); if(row){ //提示是否删除 $.messager.confirm("提示","是否删除该车辆信息",function(flag){ if(flag){ //发送Ajax请求,通过控制器执行删除车辆操作 $.post("busCarsController/removeBusCars",{'carnumber':row.carnumber},function(result){ if(result>0){ //删除成功重新加载表格数据 $("#busCarsManger_dg").datagrid("reload"); }else{ $.messager.alert("警告","删除失败","error"); } }) } }) }else //提示请选中至少一行 $.messager.alert("提示","请选中当前信息表的一行数据","info"); } //修改车辆信息 function editCars(){ //当数据表格被选中 var row= $('#busCarsManger_dg').datagrid('getSelected'); if(row){ //执行修改操作,打开修改对话框 $("#busCarsManger_dlg").dialog("open").dialog("center").dialog("setTitle","修改汽车信息") //加载当前选中信息行的数据,在表单一中回显 $("busCarsManger_fm").form("load",row); //表单二中图片的回显,不是用append方法,是因为每次点击修改就会加一个图片,故只用文本显示方法html $("#sp1").html("<img src='images/"+result.url+"'width='80px'/>") //点击保存时,实现修改操作,跳转到当前车辆信息表 url:"busCarsController/changeBusCars"; }else{ $.messager.alert("提示","请选中当前信息表的一行数据","info"); } } //文件上传的操作 function fileUpload(){ //提交form表单 $('#fm2').form('submit',{ url: "busCarsController/fileUpload", success: function(result){ var result=eval('('+result+')'); if(result.url){ //防止在执行修改车辆信息操作,上传图片时,需要清空表单二的图片,防止出现两个图片 $("#sp1").empty(); //显示图片 $("#sp1").append("<img src='images/"+result.url+"'width='80px'/>") //将图片名字赋值给隐藏域 $("#carimg").val("result.url"); }else{ $.messager.alert("提示","图片上传失败","error"); } } }); } //保存车辆信息 function saveCars(){ //获得表单的所有内容 var val =$("busCarsManger_fm").serialize(); $.post(url,val,function(result){ if(result>0){ //关闭当前的对话框 $("#busCarsManger_dlg").dialog("close") //刷新后面的表格 $("#busCarsManger_dg").datagrid("reload"); } }) } 添加车辆信息 function newCars(){ //添加新增对话框信息 $("#busCarsManger_dlg").dialog("open").dialog("center").dialog("setTitle","新增汽车") //清除表单之前的内容 $("busCarsManger_fm").form("clear") //清除图片表单项,要不然下次打开还在 $("#fm2").form("clear") //清除图片显示 $("#sp1").empty(); url="busCarsController/saveBusCars"; } function showImage(val){ return "<img src='images/"+val+"' width='80px'/>"; } </script> </body>
jsvalidation用法,小白提问!!
1、使用jsvalidation没效果,点击表单提交没验证直接到了下一页,按F12显示 HTTP404: 找不到 - 服务器尚未找到与请求的 URI (统一资源标识符)匹配的任何内容。 GET - http://localhost:8081/js/validation-framework.js 不知道啥原因,jsvalidation的三个dtd xml 和js代码是老师给的,说是要写一个什么正则表达式,不会改 求解答 2 查过资料 web。xml中没有设置那个什么过滤那个 3下面是framework。js的代码,看不懂 ``/* * JavaScript Validation Framework * * Author: Michael Chen(mechiland) on 2004/03 * This software is on the http://www.cosoft.org.cn/projects/jsvalidation * for update, bugfix, etc, you can goto the homepage and submit your request * and question. * Apache License 2.0 * You should use this software under the terms. * * Please, please keep above words. At least ,please make a note that such as * "This software developed by Michael Chen(http://www.jzchen.net)" . * $Id: validation-framework.js,v 1.7 2004/04/30 05:33:29 jzchen Exp $ */ /** Config Section, Config these fields to make this framework work. **/ // If there is only one config file in your system, use this property. otherwise, use // ValidationFramework.init("configfile") // instead. var ValidationRoot = "/LoginServletProjectFour/js/"; // the field style when validation fails. it aim to provide more beautiful UI and more good // experience to the end-user. // NOTE: this will be buggy. Please report the error to me. var ValidationFailCssStyle = "border:2px solid #FFCC88;"; //Validation function. The entry point of the framework. function doValidate(formRef) { try { var formId = formRef; if (typeof (formRef) == "string") { formId = formRef; } else if (typeof (formRef) == "object") { formId = formRef.getAttribute("id"); } var form = FormFactory.getFormFromId(formId); if (form != null) { return ValidationFramework.validateForm(form); } else { return false; } } catch (e) { ValidationFramework.exception(e.name+":" +e.description); return false; } } /**===================================================================**/ /* * JSValidation Framework Code Started * * Please do not modify the code unless you are very familiar with JavaScript. * The best way to solve problem is report the problem to our project page. * url: http://cosoft.org.cn/projects/jsvalidation */ // The Xml document. To process cross-browser. Thanks Eric. function XmlDocument() {} XmlDocument.create = function () { if (document.implementation && document.implementation.createDocument) { return document.implementation.createDocument("", "", null); } else if (window.ActiveXObject) { try { var prefix = ["MSXML2", "MSXML", "Microsoft", "MSXML3"]; for (var i = 0; i < prefix.length; i++) { //return new ActiveXObject(prefix[i] + ".DomDocument"); var obj = new ActiveXObject(prefix[i] + ".DomDocument"); if (obj == null || typeof(obj) == 'undefined') { continue; } else { return obj; } } } catch (e) { //^_^ throw new Error("My God, What version of IE are you using? IE5&+ is requiered."); } } else throw new Error("Cannot create DOM Document!"); } function ValidationFramework() {} ValidationFramework._validationCache = null; ValidationFramework._currentForm = null; ValidationFramework._userLanguage="auto"; /** * Validate a form. * NOTE: the form is Framework virture form, not the HTML Form. * Html Form can be transform to Virture form by * FormFactory.getFormFromId(htmlFormId); * See the doc for more information. * @param form the virtual form. */ ValidationFramework.validateForm = function(fform) { ValidationFramework._currentForm = fform; var failFields = []; var id = fform.getId(); var showError = fform.getShowError(); var showType = fform.getShowType(); var br = null; if (showError != "alert") { br = "<br />"; } else { br = "\n"; } var errorStrArray = []; var ret = false; var formObj = document.getElementById(id); var fields = fform.getFields(); var rightnum = 0; for (var i = 0; i < fields.length; i++) { var retVal = ValidationFramework.validateField(fields[i]); var fo=formObj[fields[i].getName()]; if (typeof (fo) !='undefined' && fo != null && typeof(fo.type) != "undefined") { fo.style.cssText = ""; } if (retVal != "OK") { errorStrArray[errorStrArray.length] = retVal; failFields[failFields.length] = formObj[fields[i].getName()]; } else { rightnum ++; } } if (rightnum == fields.length) { ret = true; } if (errorStrArray.length > 0) { if (showError == "alert") { if (showType == "first") { alert(errorStrArray[0]); } else { alert(errorStrArray.join(br)); } } else { var errObj = document.getElementById(showError); if (showType == "first") { errObj.innerHTML = errorStrArray[0]; } else { errObj.innerHTML = errorStrArray.join(br); } } if (typeof (failFields[0]) !='undefined' && failFields[0] != null && typeof(failFields[0].type) != "undefined") { failFields[0].focus(); } for (var i = 0; i < failFields.length; i++) { var o = failFields[i]; if ( typeof (o) !='undefined' && o != null && typeof(o.type) != "undefined") { o.style.cssText = ValidationFailCssStyle; } } } return ret; } /** * Validation the field * @param filed the field you want to validate. */ ValidationFramework.validateField = function(field) { var depends = field.getDepends(); var retStr = "OK"; for (var i = 0; i < depends.length; i++) { if (!ValidationFramework.validateDepend(field, depends[i])) { retStr = ValidationFramework.getErrorString(field, depends[i]); return retStr; //Break; } } return retStr; } /** * Validate the field depend. * This function dispatch the various depends into ValidateMethodFactory.validateXXX */ ValidationFramework.validateDepend = function(field, depend) { if (depend.getName() == "required") { return ValidateMethodFactory.validateRequired(field, depend.getParams()); } else if (depend.getName() == "integer") { return ValidateMethodFactory.validateInteger(field, depend.getParams()); } else if (depend.getName() == "double") { return ValidateMethodFactory.validateDouble(field, depend.getParams()); } else if (depend.getName() == "commonChar") { return ValidateMethodFactory.validateCommonChar(field, depend.getParams()); } else if (depend.getName() == "chineseChar") { return ValidateMethodFactory.validateChineseChar(field, depend.getParams()); } else if (depend.getName() == "minLength") { return ValidateMethodFactory.validateMinLength(field, depend.getParams()); } else if (depend.getName() == "maxLength") { return ValidateMethodFactory.validateMaxLength(field, depend.getParams()); } else if (depend.getName() == "email") { return ValidateMethodFactory.validateEmail(field, depend.getParams()); } else if (depend.getName() == "date") { return ValidateMethodFactory.validateDate(field, depend.getParams()); } else if (depend.getName() == "time") { return ValidateMethodFactory.validateTime(field, depend.getParams()); } else if (depend.getName() == "mask") { return ValidateMethodFactory.validateMask(field, depend.getParams()); } else if (depend.getName() == "integerRange") { return ValidateMethodFactory.validateIntegerRange(field, depend.getParams()); } else if (depend.getName() == "doubleRange") { return ValidateMethodFactory.validateDoubleRange(field, depend.getParams()); } else if (depend.getName() == "equalsField") { return ValidateMethodFactory.validateEqualsField(field, depend.getParams()); } else { ValidationFramework.exception("还未实现该依赖: " + depend.getName()); return false; } } // hold the current config file var _validationConfigFile = ""; ValidationFramework.getDocumentElement = function() { if (ValidationFramework._validationCache != null) { return ValidationFramework._validationCache; } var file = ""; if (_validationConfigFile != "") { file = _validationConfigFile; } else { file = ValidationRoot + "validation-config.xml"; } var xmlDoc = XmlDocument.create(); xmlDoc.async = false; // Damn!!! it cost me half an hour to fix it! xmlDoc.load(file); if (xmlDoc.documentElement == null) { ValidationFramework.exception("配置文件读取错误,请检查。"); return null; } // TODO: parse the document if it's a valid document. ValidationFramework._validationCache = xmlDoc.documentElement; var lang=ValidationFramework._validationCache.getAttribute("lang"); ValidationFramework._userLanguage = (lang==null) ? "auto" : lang; return ValidationFramework._validationCache; } ValidationFramework.init = function(configFile) { _validationConfigFile = configFile; ValidationFramework.getDocumentElement(); } ValidationFramework.getAllForms = function() { var vforms = []; var root = ValidationFramework.getDocumentElement(); if (root != null) { var fs = root.childNodes; for (var i = 0;i < fs.length ;i++ ) { vforms[i] = new ValidationForm(fs.item(i)); } } return vforms; } ValidationFramework.getErrorString = function(field, depend) { var stringResource = null; var lang = ValidationFramework._userLanguage.toLowerCase(); //if lang == auto, get the user's browser language. if (lang == "auto") { // different browser has the different method the get the // user's language. so this is a stupid way to detect the // most common browser IE and Mozilla. if (typeof navigator.userLanguage == 'undefined') lang = navigator.language.toLowerCase(); else lang = navigator.userLanguage.toLowerCase(); } // get the language if (typeof ValidationErrorString[lang] != 'object') { stringResource = ValidationErrorString['zh-cn']; } else { stringResource = ValidationErrorString[lang]; } var dep = depend.getName().toLowerCase(); var retStr = stringResource[dep]; //If the specified depend not defined, use the default error string. if (typeof retStr != 'string') { retStr = stringResource["default"]; retStr = retStr.replace("{0}", field.getDisplayName()); return retStr; } retStr = retStr.replace("{0}", field.getDisplayName()); if (dep == "minlength" || dep == "maxlength" || dep == "date" ) { retStr = retStr.replace("{1}", depend.getParams()[0]); } else if ( dep == "equalsfield") { var eqField = field.getForm().findField(depend.getParams()[0]); if (eqField == null) { ValidationFramework.exception("找不到名称为[" + depend.getParams()[0]+"]的域,请检查xml配置文件。"); retStr = "<<配置错误>>"; } else { retStr = retStr.replace("{1}", field.getForm().findField(depend.getParams()[0]).getDisplayName()); } } else if (dep == "integerrange" || dep == "doublerange") { retStr = retStr.replace("{1}", depend.getParams()[0]); retStr = retStr.replace("{2}", depend.getParams()[1]); } return retStr; } ValidationFramework.getWebFormFieldObj = function(field) { var obj = null; if (ValidationFramework._currentForm != null) { var formObj = document.getElementById(ValidationFramework._currentForm.getId()); obj = formObj[field.getName()]; if (typeof(obj) == 'undefined') { obj = null; } } if (obj == null) { ValidationFramework.exception("在配置文件中有需要验证的域,但在实际网页表单中不存在:[name=" + field.getName() + "]。"); } return obj; } ValidationFramework.exception = function(str) { var ex = "JavaScript Validation Framework 运行时错误:\n\n"; ex += str; ex += "\n\n\n任何运行错误都会导致该域验证失败。"; alert(ex); } ValidationFramework.getIntegerValue = function(val) { var intvalue = parseInt(val); if (isNaN(intvalue)) { ValidationFramework.exception("期待一个整型参数。"); } return intvalue; } ValidationFramework.getFloatValue = function(val) { var floatvalue = parseFloat(val); if (isNaN(floatvalue)) { ValidationFramework.exception("期待一个浮点型参数。"); } return floatvalue; } /** * FormFactory * Build virture form from Html Form. */ function FormFactory() {} FormFactory.getFormFromDOM = function(dom) { var form = new ValidationForm(); form.setId(dom.getAttribute("id")); form.setShowError(dom.getAttribute("show-error")); form.setOnFail(dom.getAttribute("onfail")); form.setShowType(dom.getAttribute("show-type")); if (dom.hasChildNodes()) { var f = dom.childNodes; for (var i = 0; i < f.length; i++) { if (f.item(i) == null||typeof(f.item(i).tagName) == 'undefined' || f.item(i).tagName != 'field') { continue; } var field = FieldFactory.getFieldFromDOM(f.item(i)); if (field != null) { form.addField(field); } } } return form; } /// Get the Form from ID FormFactory.getFormFromId = function(id) { var root = ValidationFramework.getDocumentElement(); if ( root == null || (!root.hasChildNodes()) ) return null; var vforms = root.childNodes; for (var i = 0; i < vforms.length; i++) { var f = vforms.item(i); if (typeof(f.tagName) != 'undefined' && f.tagName == 'form' && f.getAttribute("id") == id) { return FormFactory.getFormFromDOM(f); } } return null; } /** * A validation form object. */ function ValidationForm() { this._fields = []; this._id = null; this._showError = null; this._onFail = null; this._showType = null; this.getFields = function() { return this._fields; } this.setFields = function(p0) { this._fields = p0; } this.getId = function() { return this._id; } this.setId = function(p0) { this._id = p0; } this.getShowError = function() { return this._showError; } this.setShowError = function(p0) { this._showError = p0; } this.getShowType = function() { return this._showType; } this.setShowType = function(p0) { this._showType = p0; } this.getOnFail = function() { return this._onFail; } this.setOnFail = function(p0) { this._onFail = p0; } // find field by it's name this.findField = function(p0) { for (var i = 0; i < this._fields.length; i++) { if (this._fields[i].getName() == p0) { return this._fields[i]; } } return null; } this.addField = function(p0) { this._fields[this._fields.length] = p0; p0.setForm(this); } } /** * A form filed. virtual. */ function ValidationField() { this._name = null; this._depends = []; this._displayName = null; this._onFail = null; this._form = null; this.getName = function() { return this._name; } this.setName = function(p0) { this._name = p0; } this.getDepends = function() { return this._depends; } this.setDepends = function(p0) { this._depends = p0; } this.getDisplayName = function() { return this._displayName; } this.setDisplayName = function(p0) { this._displayName = p0; } this.getOnFail = function() { return this._onFail; } this.setOnFail = function(p0) { this._onFail = p0; } this.getForm = function() { return this._form; } this.setForm = function(p0) { this._form = p0; } this.addDepend = function(p0) { this._depends[this._depends.length] = p0; } } ///Factory methods for create Field function FieldFactory() {} FieldFactory.getFieldFromDOM = function(dom) { var field = new ValidationField(); field.setName(dom.getAttribute("name")); field.setDisplayName(dom.getAttribute("display-name")); field.setOnFail(dom.getAttribute("onfail")); if (dom.hasChildNodes()) { var depends = dom.childNodes; for (var i = 0; i < depends.length; i++) { var item = depends.item(i); if (typeof(item.tagName) == 'undefined' || item.tagName != 'depend') { continue; } var dp = new ValidationDepend(); dp.setName(item.getAttribute("name")); dp.addParam(item.getAttribute("param0")); dp.addParam(item.getAttribute("param1")); dp.addParam(item.getAttribute("param2")); dp.addParam(item.getAttribute("param3")); dp.addParam(item.getAttribute("param4")); field.addDepend(dp); } } return field; } function FormFieldUtils() {} FormFieldUtils.findField = function(formName, fieldName) { var formArr = ValidationFramework.getAllForms(); var theForm = null; for (var i = 0; i < formArr.length; i++) { if (formArr[i].getName() == formName) { theForm = formArr[i]; } } if (theForm != null) { return theForm.findField(fieldName); } else { return null; } } /** * A validaton depend. */ function ValidationDepend() { this._name = null; this._params = []; this.getName = function() { return this._name; } this.setName = function(p0) { this._name = p0; } this.getParams = function() { return this._params; } this.setParams = function(p0) { this.params = p0; } this.addParam = function(p0) { this._params[this._params.length] = p0; } } function ValidateMethodFactory() {} ValidateMethodFactory._methods = []; ValidateMethodFactory.validateRequired = function(field, params) { var obj = ValidationFramework.getWebFormFieldObj(field); if (obj == null) return false; if (typeof(obj.type) == "undefined") { var tmp = 0; for (var i = 0; i < obj.length; i++) { if (obj[i].checked) { return true; } } return false; } if (obj.type == "checkbox" || obj.type == "radio") { return (obj.checked); } else { return !(obj.value == ""); } } ValidateMethodFactory.validateInteger = function(field, params) { var obj = ValidationFramework.getWebFormFieldObj(field); if (obj == null) return false; if (obj.value == "") return true; var exp = new RegExp("^-?\\d+$"); return exp.test(obj.value); } ValidateMethodFactory.validateDouble = function(field, params) { var obj = ValidationFramework.getWebFormFieldObj(field); if (obj == null) return false; if (obj.value == "") return true; var exp = new RegExp("^-?\\d+\.\\d+$"); return exp.test(obj.value); } ValidateMethodFactory.validateCommonChar = function(field, params) { var obj = ValidationFramework.getWebFormFieldObj(field); if (obj == null) return false; if (obj.value == "") return true; var exp = new RegExp("^[A-Za-z0-9_]*$"); return exp.test(obj.value); } ValidateMethodFactory.validateChineseChar = function(field, params) { var obj = ValidationFramework.getWebFormFieldObj(field); if (obj == null) return false; if (obj.value == "") return true; var exp = new RegExp("^[\u4E00-\u9FA5\uF900-\uFA2D]*$"); return exp.test(obj.value); } ValidateMethodFactory.validateMinLength = function(field, params) { var obj = ValidationFramework.getWebFormFieldObj(field); if (obj == null) return false; var v = ValidationFramework.getIntegerValue(params[0]); return (obj.value.length >= v); } ValidateMethodFactory.validateMaxLength = function(field, params) { var obj = ValidationFramework.getWebFormFieldObj(field); if (obj == null) return false; var v = ValidationFramework.getIntegerValue(params[0]); return (obj.value.length <= v); } ValidateMethodFactory.validateEmail = function(field, params) { var obj = ValidationFramework.getWebFormFieldObj(field); if (obj == null) return false; return ValidateMethodFactory.__checkEmail(obj.value); } ValidateMethodFactory.validateDate = function(field, params) { var obj = ValidationFramework.getWebFormFieldObj(field); if (obj == null) return false; if (obj.value == "") return true; var value = obj.value; var datePattern = params[0]; var MONTH = "mm"; var DAY = "dd"; var YEAR = "yyyy"; var orderMonth = datePattern.indexOf(MONTH); var orderDay = datePattern.indexOf(DAY); var orderYear = datePattern.indexOf(YEAR); var bValid = true; var dateRegexp = null; if ((orderDay < orderYear && orderDay > orderMonth)) { var iDelim1 = orderMonth + MONTH.length; var iDelim2 = orderDay + DAY.length; var delim1 = datePattern.substring(iDelim1, iDelim1 + 1); var delim2 = datePattern.substring(iDelim2, iDelim2 + 1); if (iDelim1 == orderDay && iDelim2 == orderYear) { dateRegexp = new RegExp("^(\\d{2})(\\d{2})(\\d{4})$"); } else if (iDelim1 == orderDay) { dateRegexp = new RegExp("^(\\d{2})(\\d{2})[" + delim2 + "](\\d{4})$"); } else if (iDelim2 == orderYear) { dateRegexp = new RegExp("^(\\d{2})[" + delim1 + "](\\d{2})(\\d{4})$"); } else { dateRegexp = new RegExp("^(\\d{2})[" + delim1 + "](\\d{2})[" + delim2 + "](\\d{4})$"); } var matched = dateRegexp.exec(value); if(matched != null) { if (!ValidateMethodFactory.__isValidDate(matched[2], matched[1], matched[3])) { bValid = false; } } else { bValid = false; } } else if ((orderMonth < orderYear && orderMonth > orderDay)) { var iDelim1 = orderDay + DAY.length; var iDelim2 = orderMonth + MONTH.length; var delim1 = datePattern.substring(iDelim1, iDelim1 + 1); var delim2 = datePattern.substring(iDelim2, iDelim2 + 1); if (iDelim1 == orderMonth && iDelim2 == orderYear) { dateRegexp = new RegExp("^(\\d{2})(\\d{2})(\\d{4})$"); } else if (iDelim1 == orderMonth) { dateRegexp = new RegExp("^(\\d{2})(\\d{2})[" + delim2 + "](\\d{4})$"); } else if (iDelim2 == orderYear) { dateRegexp = new RegExp("^(\\d{2})[" + delim1 + "](\\d{2})(\\d{4})$"); } else { dateRegexp = new RegExp("^(\\d{2})[" + delim1 + "](\\d{2})[" + delim2 + "](\\d{4})$"); } var matched = dateRegexp.exec(value); if(matched != null) { if (!ValidateMethodFactory.__isValidDate(matched[1], matched[2], matched[3])) { bValid = false; } } else { bValid = false; } } else if ((orderMonth > orderYear && orderMonth < orderDay)) { var iDelim1 = orderYear + YEAR.length; var iDelim2 = orderMonth + MONTH.length; var delim1 = datePattern.substring(iDelim1, iDelim1 + 1); var delim2 = datePattern.substring(iDelim2, iDelim2 + 1); if (iDelim1 == orderMonth && iDelim2 == orderDay) { dateRegexp = new RegExp("^(\\d{4})(\\d{2})(\\d{2})$"); } else if (iDelim1 == orderMonth) { dateRegexp = new RegExp("^(\\d{4})(\\d{2})[" + delim2 + "](\\d{2})$"); } else if (iDelim2 == orderDay) { dateRegexp = new RegExp("^(\\d{4})[" + delim1 + "](\\d{2})(\\d{2})$"); } else { dateRegexp = new RegExp("^(\\d{4})[" + delim1 + "](\\d{2})[" + delim2 + "](\\d{2})$"); } var matched = dateRegexp.exec(value); if(matched != null) { if (!ValidateMethodFactory.__isValidDate(matched[3], matched[2], matched[1])) { bValid = false; } } else { bValid = false; } } else { bValid = false; } return bValid; } ValidateMethodFactory.validateTime = function(field, params) { ////NOT IMPLEMENT YET SINCE IT'S NOT USEFUL. return true; } ValidateMethodFactory.validateMask = function(field, params) { var obj = ValidationFramework.getWebFormFieldObj(field); if (obj == null) return false; if (obj.value == "") return true; var exp = new RegExp(params[0]); //FIXME: this method may be buggy, need more test. return exp.test(obj.value); } ValidateMethodFactory.validateIntegerRange = function(field, params) { var obj = ValidationFramework.getWebFormFieldObj(field); if (obj == null) return false; if (obj.value == "") return true; var p0 = ValidationFramework.getIntegerValue(params[0]); var p1 = ValidationFramework.getIntegerValue(params[1]); if (ValidateMethodFactory.validateInteger(field)) { var v = parseInt(obj.value); return (v >= p0 && v <= p1); } else { return false; } return true; } ValidateMethodFactory.validateDoubleRange = function(field, params) { var obj = ValidationFramework.getWebFormFieldObj(field); if (obj == null) return false; if (obj.value == "") return true; var p0 = ValidationFramework.getFloatValue(params[0]); var p1 = ValidationFramework.getFloatValue(params[1]); if (ValidateMethodFactory.validateInteger(field) || ValidateMethodFactory.validateDouble(field)) { var v = parseFloat(obj.value); return (v >= p0 && v <= p1); } else { return false; } return true; } ValidateMethodFactory.validateEqualsField = function(field, params) { var obj = ValidationFramework.getWebFormFieldObj(field); if (obj == null) return false; var formObj = document.getElementById(ValidationFramework._currentForm.getId()); var eqField = formObj[params[0]]; if (eqField != null) { return (obj.value == eqField.value) } else { return false; } } ValidateMethodFactory.__isValidDate = function(day, month, year) { if (month < 1 || month > 12) return false; if (day < 1 || day > 31) return false; if ((month == 4 || month == 6 || month == 9 || month == 11) &&(day == 31)) return false; if (month == 2) { var leap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0)); if (day>29 || (day == 29 && !leap)) return false; } return true; } /** * Reference: Sandeep V. Tamhankar (stamhankar@hotmail.com), * http://javascript.internet.com */ ValidateMethodFactory.__checkEmail = function(emailStr) { if (emailStr.length == 0) { return true; } var emailPat=/^(.+)@(.+)$/; var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"; var validChars="\[^\\s" + specialChars + "\]"; var quotedUser="(\"[^\"]*\")"; var ipDomainPat=/^(\d{1,3})[.](\d{1,3})[.](\d{1,3})[.](\d{1,3})$/; var atom=validChars + '+'; var word="(" + atom + "|" + quotedUser + ")"; var userPat=new RegExp("^" + word + "(\\." + word + ")*$"); var domainPat=new RegExp("^" + atom + "(\\." + atom + ")*$"); var matchArray=emailStr.match(emailPat); if (matchArray == null) { return false; } var user=matchArray[1]; var domain=matchArray[2]; if (user.match(userPat) == null) { return false; } var IPArray = domain.match(ipDomainPat); if (IPArray != null) { for (var i = 1; i <= 4; i++) { if (IPArray[i] > 255) { return false; } } return true; } var domainArray=domain.match(domainPat); if (domainArray == null) { return false; } var atomPat=new RegExp(atom,"g"); var domArr=domain.match(atomPat); var len=domArr.length; if ((domArr[domArr.length-1].length < 2) || (domArr[domArr.length-1].length > 3)) { return false; } if (len < 2) { return false; } return true; } ////Language Definitions var ValidationErrorString = new Object(); ////Simplified Chinese(zh-ch) ValidationErrorString["zh-cn"] = new Object(); ValidationErrorString["zh-cn"]["default"]="域{0}校验失败。"; ValidationErrorString["zh-cn"]["required"]="{0}不能为空。<br/>"; ValidationErrorString["zh-cn"]["integer"]="{0}必须是一个整数。"; ValidationErrorString["zh-cn"]["double"]="{0}必须是一个浮点数(带小数点)。"; ValidationErrorString["zh-cn"]["commonchar"] = "{0}必须是普通英文字符:字母,数字和下划线。<br/>"; ValidationErrorString["zh-cn"]["chinesechar"] = "{0}必须是中文字符。"; ValidationErrorString["zh-cn"]["minlength"]="{0}长度不能小于{1}个字符。"; ValidationErrorString["zh-cn"]["maxlength"]="{0}长度不能大于{1}个字符。" ; ValidationErrorString["zh-cn"]["invalid"]="{0}无效。"; ValidationErrorString["zh-cn"]["date"]="{0}不是一个有效日期,期待格式:{1}。"; ValidationErrorString["zh-cn"]["integerrange"]="{0}必须在整数{1}和{2}之间。"; ValidationErrorString["zh-cn"]["doublerange"]="{0}必须在浮点数{1}和{2}之间。"; ValidationErrorString["zh-cn"]["pid"]="{0}不是一个有效身份证号。"; ValidationErrorString["zh-cn"]["email"]="{0}不是一个有效的Email。"; ValidationErrorString["zh-cn"]["equalsfield"]="{0}必须和{1}一致。"; ////English(en-us) ValidationErrorString["en-us"] = new Object(); ValidationErrorString["en-us"]["default"]="Failed when validating filed {0}."; ValidationErrorString["en-us"]["required"]="{0} is required."; ValidationErrorString["en-us"]["integer"]="{0} must be a integer."; ValidationErrorString["en-us"]["double"]="{0} must be a double value. "; ValidationErrorString["en-us"]["commonchar"] = "{0} should be common ascii characters, A-Z,a-z and undercore. "; ValidationErrorString["en-us"]["chinesechar"] = "{0} must be chinese characters. "; ValidationErrorString["en-us"]["minlength"]="{0} cannot be less then {1}. "; ValidationErrorString["en-us"]["maxlength"]="{0} cannot be more then {1}. "; ValidationErrorString["en-us"]["invalid"]="{0} in invalid. "; ValidationErrorString["en-us"]["date"]="{0} is not an invalid date format: {1}. "; ValidationErrorString["en-us"]["integerrange"]="{0} should be between number {1} and {2}. "; ValidationErrorString["en-us"]["doublerange"]="{0} should be between double {1} and {2}. "; ValidationErrorString["en-us"]["pid"]="{0} is not an valid pid. "; ValidationErrorString["en-us"]["email"]="{0} is not an valid email address. "; ValidationErrorString["en-us"]["equalsfield"]="{0} should be agree with field {1}. "; // preload the validation file. //ValidationFramework.getDocumentElement();` 4xml代码 ``` <?xml version="1.0" encoding="utf-8"?> <!DOCTYPE validation-config SYSTEM "validation-config.dtd"> <validation-config lang="auto"> <form id="form1" show-error="alert" show-type="all"> <field name="name" display-name="姓名" onfail=""> <depend name="required" /> <depend name="commonChar" /> <depend name="minLength" param0="3" /> <depend name="maxLength" param0="20" /> </field> <field name="email" display-name="email邮箱"> <depend name="required" /> <depend name="email" /> </field> <field name="age" display-name="年龄"> <depend name="required" /> </field> <field name="protime" display-name="编程时间"> <depend name="required" /> </field> <field name="os" display-name="使用的操作系统"> <depend name="required" /> </field> <field name="lang" display-name="使用的编程语言"> <depend name="required" /> </field> <field name="editor1" display-name="建议"> <depend name="required" /> </field> </form> </validation-config> ``` 5jsp代码 ``` <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> <% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <base href="<%=basePath%>"> <title>My JSP 'Login.jsp' starting page</title> <meta http-equiv="pragma" content="no-cache"> <meta http-equiv="cache-control" content="no-cache"> <meta http-equiv="expires" content="0"> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv="description" content="This is my page"> <!-- <link rel="stylesheet" type="text/css" href="styles.css"> --> </head> <script type='text/javascript' src='ckeditor/ckeditor.js'></script> <script type='text/javascript' src='/js/validation-framework.js'></script> <body> <h1>潜在用户网络调查</h1> <form action='LoginServlet' name='form1' id='form1' method='post' onSubmit="return doValidate(this)"> 姓名:<input type='text' name='name' value='' /><br/> EMAIL:<input type='text' name='email' value=''/><br/> 年纪:<input type='radio' name='age' value='小于18' />小于18 <input type='radio' name='age' value='18-25'/>18-25 <input type='radio' name='age' value='26-40'/>26-40 <input type='radio' name='age' value='大于40'/>大于40<br/> 编程时间:<select name='protime'> <option value='6-12月' >6-12月</option> <option value='12-24月'>12-24月</option> <option value='24月以上'>24月以上</option> </select><br/> 使用操作系统:<select name='os' multiple='multiple' size='6'> <option value='Win XP'>Win XP</option> <option value='Win 2000/2003'>Win 2000/2003</option> <option value='Linux'>Linux</option> <option value='FreeBSD'>FreeBSD</option> <option value='Mac OS'>Mac OS</option> <option value='Other'>Other</option> </select><br/> 使用的编程语言:<input type='checkbox' name='lang' value='C'/>C <input type='checkbox' name='lang' value='C++'/>C++ <input type='checkbox' name='lang' value='C#'/>C# <input type='checkbox' name='lang' value='PYTHON'/>PYTHON <input type='checkbox' name='lang' value='JAVA'/>JAVA <input type='checkbox' name='lang' value='VB'/>VB <input type='checkbox' name='lang' value='DEPHI'/>DEPHI<br/> 建议:<textarea class='ckeditor' cols='50' id='editor1' name='editor1' rows='10'></textarea><br/> <input type='submit' value='提交'> <input type='reset' value='重置'> <input type='hidden' name='ring' value='normal'><br/> <% HttpSession hs=request.getSession(true); hs.setAttribute("write", "yes"); %> </form> </body> </html> ```
form提交后,action中怎么获取select下拉框的选中值
点击按钮后如果选择.com表单应该是 http://我的域名/nav/c1.php?id= 如果选择.cn应该是 http://我的域名/nav/c2.php?id= 小白不懂 想问下怎么实现 ``` <form action="这里应该填什么才能保证选择其他选项的时候自动变成option value后的内容" method="get" name="form"> <div class="form-group"> <div class="input-group"> <input type="text" name="id" class="form-control" placeholder="请输入删除后缀的域名"> <div class="input-group-addon"> <select id="select" onchange="change();"> <option value="./nav/c1.php" selected>.com</option> <option value="./nav/c2.php">.cn</option> <option value="./nav/c3.php">.cc</option> <option value="./nav/c4.php">.me</option> <option value="./nav/c5.php">.pw</option> <option value="./nav/c6.php">.top</option> <option value="./nav/c7.php">.net</option> <option value="./nav/c8.php">.bid</option> <option value="./nav/c9.php">.online</option> <option value="./nav/a1.php">.xyz</option> </select> </div> </div> </div> <button type="submit" class="btn btn-success btn-block">生成短链接</button> ```
input表单查询,不输入值时后台显示 数据类型转换错误,
前台代码:订单号: <input class="easyui-textbox" name="oid" id="select" style="width:150px"> 后台代码:![图片说明](https://img-ask.csdn.net/upload/201603/15/1458029094_89739.png) 原订单号为long型,后台转为字符串后执行的查询操作。 正常输入订单号查询时,可以查到,但是如果不输入值,直接点击查询会报错。好像是数据类型转换错误。不过我在Java后台不是已经直接做了转换的,怎么还是这样,求解答 严重: Servlet.service() for servlet [spring] in context with path [/xxcnew] threw exception [Request processing failed; nested exception is org.springframework.validation.BindException: org.springframework.validation.BeanPropertyBindingResult: 1 errors Field error in object 'order' on field 'oid': rejected value []; codes [typeMismatch.order.oid,typeMismatch.oid,typeMismatch.long,typeMismatch]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [order.oid,oid]; arguments []; default message [oid]]; default message [Failed to convert property value of type 'java.lang.String' to required type 'long' for property 'oid'; nested exception is java.lang.NumberFormatException: For input string: ""]] with root cause
获取页面控件时,如何避免那些不是表单中的控件
在利用$('input, select, textarea').each(function(index)获取页面控件时,如何避免那些不是表单中的控件,如本例中的xformvalues,它是window窗口中的控件。 $('input, select, textarea').each(function(index){ var input = $(this); var id=input.attr('id'); var value=undefined; var type=input.attr('type'); var hidden=input.attr('hidden'); if (id!=undefined){ if (type=='text' && hidden!='hidden'){ value=input.textbox('getValue'); }else if (type=='combobox'){ value=input.combobox('getValue'); }else if (type=='checkbox'){ if (input.is(':checked')) value=input.attr('xtext'); }else if (type!='button'){ value=input.val(); } if (value!=undefined){ if (data!='') data+=','; data+='"'+id+'":"'+value+'"'; console.log(id+'----'+type+'----'+value); } } }); data='{'+data+'}'; $("#xformvalues").val(data);
servlet跳转到jsp,怎么把传入的值赋到里面的jsp表单的text中
``` add.jsp <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>计算器</title> <script type="text/javascript" src="result.js"> </script> </head> <body> <% String first = request.getParameter("first"); String second = request.getParameter("second"); %> <form action="/add" method="get"> <input id="first" type="text" name="first" value=first> <select name="fuhao"> <option>+</option> <option>-</option> <option>*</option> <option>/</option> </select> <input id="second" type="text" name="second" value=second> <input id="count" type="submit" value="=" onclick="add()"> <input id="result" type="text"> </form> </body> </html> addServlet.java package cn.itsource.servletadd; import java.io.IOException; import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @WebServlet("/add") public class AddServlet extends HttpServlet{ private static final long serialVersionUID = 1L; @Override protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { // 得到传来的第一个加数 String first = req.getParameter("first"); // System.out.println(first); Integer firstadd =null; // 判断输入的值是否是空值,并转换成Integer if(first!=null){ firstadd = Integer.parseInt(first); } // System.out.println(firstadd); // 得到第二个加数 String second = req.getParameter("second"); Integer secondadd = null; // System.out.println(second); // 判断输入的值是否是空值,并转换成Integer if(second!=null){ secondadd = Integer.parseInt(second); } // 得到传入的符号是什么 String countadd = req.getParameter("fuhao"); // System.out.println(countadd); // 得到最后的结果 String result = req.getParameter("result"); if("+".equals(countadd)){ Integer rel = firstadd + secondadd; result = rel.toString(); } if("-".equals(countadd)){ Integer rel = firstadd - secondadd; result = rel.toString(); } if("*".equals(countadd)){ Integer rel = firstadd * secondadd; result = rel.toString(); } if("/".equals(countadd)){ Integer rel = firstadd / secondadd; result = rel.toString(); } // System.out.println(result); req.getRequestDispatcher("/add.jsp").forward(req, resp); } } 怎么把跳转的值设置到上面的表单中的text里面 ```
html 字体标签 列表 表格 表单
一、字体标签 1、字体标签使用<font color="" face="" size="">...</font>表示 color属性:表示字体颜色 取值:英文 red blue yellow green black pink white 十六进制 #开头 前两位控制红色 中间两位控制绿色 后两位控制蓝色 #00 00 00 十六进制的取值0-F face属性:字体格式 比如:宋体、微软雅黑 size属性:字体大小 取值:1-7 可以为负数,为负数字字体会变小,超出7以最大值为准 默认为3 (官方取值1-7,无特殊情况,不要使用负数) 加粗字:<b>...</b>标签中的内容字体会加粗 斜体字:<i>...</i>标签中的内容字体会倾斜 下划线字:<u>...</u>标签中的内容字体会有下划线 二、列表 1、有序列表 order list <ol></ol>表示有序列表 <li></li> list item 列表元素 <ol type="1|A|a|I|i"> <li></li> </ol> type属性取值: 1 阿拉伯数字 默认 A 大写的英文字母 a 小写的英文字母 I 大写的罗马数字 i 小写的罗马数字 2、无序列表 unordered list <ul></ul>表示无序列表 <li></li> list item 列表元素 <ul type="disc|circle|square|none"> <li></li> </ul> type属性取值:disc 实心圆 默认 circle 空心圆 square 实心方块 none 不修饰 一级默认实心圆 二级默认空心圆 三级默认实心方块 3、自定义列表 definition list <dl></dl> 自定义列表 <dt></dt> 自定义标题 definition title <dd></dd> 自定义描述 definition description <dl> <dt>...</dt> <dd></dd> </dl> 三、表格 <table> <tr> <td>...</td> </tr> </table> table标签:代表表格 tr标签:代表一行 注:只有单元格才能放东西,其他的不能放任何元素 thead标签:表格的头部 tbody标签:表格的内容 tfoot标签:表格的尾部 caption标签:表格的标题 boder属性:表格的边框 width属性:宽度 height属性:高度 align属性:对齐方式,取值:左、中、右 cellspacing属性:单元格与单元格之间的间隙 外边距 cellpadding属性:单元格与内容之间的间隙 内边距 bgcolor属性:表格背景颜色 colspan属性:列合并 rowspan属性:行合并 四、表单 表单:把客户端页面数据提交给服务器端<form></form> 格式:<form action="" method="" type=""> <input /> </form> form:表单标签 action属性:提交到服务器端的地址 method属性:提交方式,取值:get 默认 post input标签:表单元素 type属性:定义表单中的元素类型,取值如下: text 文本输入框 默认 password 密码框 radio 单选框 必须每个单选框name属性相同 chackbox 复选框 必须每个复选框name属性相同 submit 提交按钮 会提交表单 reset 重置按钮 会重置表单 button 普通按钮 image 图片按钮 会提交表单 hidden 隐藏域 file 文件上传 name属性:元素的名称 服务器端是通过name属性获取input框的值 value属性:元素的值 readonly属性:只读 会传输到服务器 disabled属性:禁用 不会传输到服务器 maxlength属性:最大输入字符个数 placeholder属性:提示语 checked属性:是否选中 select标签:下拉列表 size属性:显示下拉列表中几个值 multicol标签:可以选中多个选项 option标签:下拉列表中的选项 格式:<select> <option>...</option> </s/elect> textarea标签:文本区域框 rows属性:行数 cols属性:列数 URL与参数用?连接 参数与参数之间用&
表单 选择其他后要求必填文本
如下: 选择标签select中有一个option为“其他”,现想实现如果选择为“其他”选项的时候,显示一个“input type="text" ”的输入框,然后对这个输入框做失去焦点验证是否有值的功能。请各位大大帮忙下(JS不佳,最好详细点) 部分代码片段如下 ![图片说明](https://img-ask.csdn.net/upload/201708/21/1503280683_364858.png) ``` <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf8_decode" /> <title>无标题文档</title> </head> <script> <!--故障类型选择“其他”的时候弹出文本框--> function select_change() { if (document.getElementById("select_id").value == "其他") { document.getElementById("input_text").style.display = "block"; } else { document.getElementById("input_text").style.display = "none"; } } function show() { var input_text = document.getElementById("input_text").value; if (input_text.length > 0) { document.getElementById("input_text").style.display = "none"; } else { document.getElementById("input_text").style.display = "block"; } } </script> <body> <form name="form1" action="update2.php" method="post"> <table > <tr> <td>故障描述</td> <td> <select name="question" onchange="select_change()" id="select_id"> <option>花屏</option> <option>3.5mm接口无法使用</option> <option>电源接口接触不良</option> <option>电脑蓝屏</option> <option>提示需运行“chkdsk”工具</option> <option>其他</option> </select> <input type="text" id="input_text" style="display: none" name="question2" onblur="show()"/> <strong id="input_text" style="color: red;display: none;">您输入的信息为空!</strong> </td> </tr> </table> </form> </body> </html> ```
springMVC中如何用对象来接收前端序列化的表单?
前端表单: <form id="patientForm" method="post" enctype="application/json"> <div> &nbsp&nbsp<label for="name">姓名:</label> <input class="easyui-validatebox" type="text" name="name" data-options="required:true" /> </div> <div> <label for="birthday">出生日期:</label> <input id="birthday" type= "text" class= "easyui-datebox" name="birthday" required ="required" /> </div> <div> <label for="IdNumber">身份证号:</label> <input id="IdNumber" class="easyui-validatebox" type="text" name="IdNumber" data-options="required:true" /> </div> <div> <label for="tel">联系电话:</label> <input id="tel" class="easyui-validatebox" type="text" name="tel" data-options="required:true" /> </div> <div> &nbsp&nbsp<label for="sex">性别:</label> <select id="sex" class="easyui-combobox" name="sex" style="width:280px;"> <option value="">请选择......</option> <option value="男">男</option> <option value="女">女</option> </select> </div> <div> <label for="address">家庭住址:</label> <input id="address" class="easyui-validatebox" type="text" name="address" data-options="required:true" /> </div> <div> <label for="cli_doc">门诊医生:</label> <select id="cli_doc" class="easyui-combobox" name="cli_doc" style="width:280px" data-options="valueField:'id',textField:'text'"> <!-- <option>请选择......</option> --> </select> </div> <input id="reg_doc" name="reg_doc" type="hidden"/> <div> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp <a id="btn" href="javascript:add()" class="easyui-linkbutton" data-options="iconCls:'icon-add'">添加并挂号</a> </div> </form> ``` 用serialize()方法序列化表单之后用ajax传到后台,但总是传不过去,求教方法 ```
submit按钮同时有onclick事件,如何让onclick的方法实行在表单提交之后
如下:form表单中的submit按钮同时有onclick事件,如何让onclick的方法运行在submit之后,曾经尝试过写一个javascript方法来自定一个wait函数,但是虽然等待了,但submit还是在onclick之后运行的,希望了解这块儿的朋友帮忙看一下,急急急,在线等 ``` <form action="api/Upload/" method="post" ng-submit="processForm()"> <input type="file" id="file" name="imgUploader" ngf-select="true" ng-model="filemodel" style="display: none" multiple/> <input type="submit" name="submit" onclick="addjson()" /> </form> ```
JSP在页面内显示所有表单信息,对某一行进行修改操作,结果所有数据都进行传值了?
我想对这个页面中的一项信息进行修改,原显示是这样的![图片说明](https://img-ask.csdn.net/upload/201912/07/1575686265_53 8116.jpg) 然后问题来了,我对选中对待某一行做了修改操作后,网页传值是这样的: ``` lhost:8084/JavaWebTest6/Subscripton.jsp?mailserver=qq.com&mailusernae=zsq&mailpassword=1&mailservertype=1&Username=null&mailserver=126.com&mailusernae=zs&mailpassword=1&mailservertype=2&Username=null&mailserver=136.com&mailusernae=ad&mailpassword=1&mailservertype=POP3&Username=null&mailserver=qq.com&mailusernae=w&mailpassword=q&mailservertype=1&Username=null&mailserver=136.com&mailusernae=e&mailpassword=e&mailservertype=e&Username=null&mailserver=qq.com&mailusernae=q&mailpassword=q&mailservertype=q&Username=null&Mailserver=&Mailusernae=&Mailpassword=&Mailservertype=&Username=null* ``` 很明显,把所有值都传过来了,下面是显示页的代码(有标注的地方是有问题的地方): ``` <%-- Document : mainMenu Created on : 2019-11-7, 11:28:27 Author : Administrator --%> <%@page language ="java" pageEncoding="UTF-8"%> <%@page import="java.sql.*"%> <!DOCTYPE html> <html> <head> <title>用户账号管理系统</title> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> </head> <body> <div></div> <h2><b>用户账号及邮箱信息维护界面</b></h2> <table frame="hsides"> <% String username=request.getParameter("name"); out.println("用户名:"+username); %> <tr> <a href="account.jsp?username=<%=username%>">修改密码</a><br> </tr> <tr><br></tr> <tr> <td><input type="text" disabled="true" value="邮箱主机"></td> <td><input type="text" disabled="true" value="邮箱用户名"></td> <td><input type="text" disabled="true" value="邮箱密码"></td> <td><input type="text" disabled="true" value="邮箱服务器类型"></td> </tr> <% Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection conn = DriverManager.getConnection("jdbc:odbc:ACCountdb"); Statement stat = conn.createStatement(); String sql = "SELECT * FROM TB_SUBSCRIPTION WHERE USERNAME='"+username+"'"; ResultSet rs = stat.executeQuery(sql); //这里写的循环直接导致后面传值的时候,所有表中数据都传过去了 while (rs.next()){ //String username = rs.getString("USERNAME"); String mailserver = rs.getString("MAILSERVER"); String mailusernae = rs.getString("MAILUSERNAE"); String mailpassword = rs.getString("MAILPASSWORD"); String mailservertype = rs.getString("MAILSERVERTYPE"); %> <form action="Subscripton.jsp"> <tr> <br> <td><input type="text" value='<%=mailserver%>' name="mailserver" ></td> <td><input type="text" value='<%=mailusernae%>' name="mailusernae"></td> <td><input type="text" value='<%=mailpassword%>' name="mailpassword"></td> <td><input type="text" value="<%=mailservertype%>" name="mailservertype"></td> <td><input type="submit" value="修改邮箱信息"></td> <td><a href="delSubscription.jsp?mailserver=<%=mailserver%>&mailusernae=<%=mailusernae%>">删除</a></td> <td><input name="Username" value='<%=username%>'</td> </tr> <% } stat.close(); conn.close(); %> <form action="addSubscription.jsp"> <tr> <br> <td><input type="text" name="Mailserver"></td> <td><input type="text" name="Mailusernae"></td> <td><input type="password" name="Mailpassword"></td> <td><input type="text" name="Mailservertype"></td> <td><input type="submit" value="添加新邮箱"></td> <td><input name="Username" value='<%=username%>'</td> </tr> </form> </table> <a href="login.jsp">退出</a> </body> </html> ``` 这是修改页的代码: ``` <%-- Document : Subscripton Created on : 2019-12-7, 10:01:00 Author : Administrator --%> <%@page language="java" pageEncoding="UTF-8"%> <%@page import="java.sql.*"%> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>用户账号管理系统</title> </head> <body> <% String username=request.getParameter("Username"); String mailserver=request.getParameter("mailserver"); String mailusernae=request.getParameter("mailusernae"); %> <form action="editSubscripton.jsp?mailserver=<%=mailserver%>&mailusernae=<%=mailusernae%>"> 用户名:<input type="text" name="Username" value="<%=username%>"><br><br> 邮箱密码:<input type="text" name="mailpassword">*<br><br> 邮箱服务器类型: <input type="text" name="mailservertype">*<br><br> <input type="submit" value="修改"> <input type="reset" value="重置"> </form> <a href="mainMenu.jsp">返回</a> </body> </html> ``` 希望能得到解答!感谢!!
大学四年自学走来,这些私藏的实用工具/学习网站我贡献出来了
大学四年,看课本是不可能一直看课本的了,对于学习,特别是自学,善于搜索网上的一些资源来辅助,还是非常有必要的,下面我就把这几年私藏的各种资源,网站贡献出来给你们。主要有:电子书搜索、实用工具、在线视频学习网站、非视频学习网站、软件下载、面试/求职必备网站。 注意:文中提到的所有资源,文末我都给你整理好了,你们只管拿去,如果觉得不错,转发、分享就是最大的支持了。 一、电子书搜索 对于大部分程序员...
【JSON解析】浅谈JSONObject的使用
简介 在程序开发过程中,在参数传递,函数返回值等方面,越来越多的使用JSON。JSON(JavaScript Object Notation)是一种轻量级的数据交换格式,同时也易于机器解析和生成、易于理解、阅读和撰写,而且Json采用完全独立于语言的文本格式,这使得Json成为理想的数据交换语言。 JSON建构于两种结构: “名称/值”对的集合(A Collection of name/va...
《MySQL 性能优化》之理解 MySQL 体系结构
本文介绍 MySQL 的体系结构,包括物理结构、逻辑结构以及插件式存储引擎。
程序员请照顾好自己,周末病魔差点一套带走我。
程序员在一个周末的时间,得了重病,差点当场去世,还好及时挽救回来了。
卸载 x 雷某度!GitHub 标星 1.5w+,从此我只用这款全能高速下载工具!
作者 | Rocky0429 来源 | Python空间 大家好,我是 Rocky0429,一个喜欢在网上收集各种资源的蒟蒻… 网上资源眼花缭乱,下载的方式也同样千奇百怪,比如 BT 下载,磁力链接,网盘资源等等等等,下个资源可真不容易,不一样的方式要用不同的下载软件,因此某比较有名的 x 雷和某度网盘成了我经常使用的工具。 作为一个没有钱的穷鬼,某度网盘几十 kb 的下载速度让我...
只因接了一个电话,程序员被骗 30 万!
今天想给大家说一个刚刚发生在我身边的一起真实的诈骗经历,我的朋友因此被骗走30万。注:为了保护当事人隐私,部分情节进行了修改。1平安夜突来的电话开始以为就像普通的诈骗一样,想办法让你把钱...
我一个37岁的程序员朋友
周末了,人一旦没有点事情干,心里就瞎想,而且跟几个老男人坐在一起,更容易瞎想,我自己现在也是 30 岁了,也是无时无刻在担心自己的职业生涯,担心丢掉工作没有收入,担心身体机能下降,担心突...
python自动下载图片
近日闲来无事,总有一种无形的力量萦绕在朕身边,让朕精神涣散,昏昏欲睡。 可是,像朕这么有职业操守的社畜怎么能在上班期间睡瞌睡呢,我不禁陷入了沉思。。。。 突然旁边的IOS同事问:‘嘿,兄弟,我发现一个网站的图片很有意思啊,能不能帮我保存下来提升我的开发灵感?’ 作为一个坚强的社畜怎么能说自己不行呢,当时朕就不假思索的答应:‘oh, It’s simple. Wait for me for a ...
一名大专同学的四个问题
【前言】   收到一封来信,赶上各种事情拖了几日,利用今天要放下工作的时机,做个回复。   2020年到了,就以这一封信,作为开年标志吧。 【正文】   您好,我是一名现在有很多困惑的大二学生。有一些问题想要向您请教。   先说一下我的基本情况,高考失利,不想复读,来到广州一所大专读计算机应用技术专业。学校是偏艺术类的,计算机专业没有实验室更不用说工作室了。而且学校的学风也不好。但我很想在计算机领...
复习一周,京东+百度一面,不小心都拿了Offer
京东和百度一面都问了啥,面试官百般刁难,可惜我全会。
Java 14 都快来了,为什么还有这么多人固守Java 8?
从Java 9开始,Java版本的发布就让人眼花缭乱了。每隔6个月,都会冒出一个新版本出来,Java 10 , Java 11, Java 12, Java 13, 到2020年3月份,...
达摩院十大科技趋势发布:2020 非同小可!
【CSDN编者按】1月2日,阿里巴巴发布《达摩院2020十大科技趋势》,十大科技趋势分别是:人工智能从感知智能向认知智能演进;计算存储一体化突破AI算力瓶颈;工业互联网的超融合;机器间大规模协作成为可能;模块化降低芯片设计门槛;规模化生产级区块链应用将走入大众;量子计算进入攻坚期;新材料推动半导体器件革新;保护数据隐私的AI技术将加速落地;云成为IT技术创新的中心 。 新的画卷,正在徐徐展开。...
轻松搭建基于 SpringBoot + Vue 的 Web 商城应用
首先介绍下在本文出现的几个比较重要的概念: 函数计算(Function Compute): 函数计算是一个事件驱动的服务,通过函数计算,用户无需管理服务器等运行情况,只需编写代码并上传。函数计算准备计算资源,并以弹性伸缩的方式运行用户代码,而用户只需根据实际代码运行所消耗的资源进行付费。Fun: Fun 是一个用于支持 Serverless 应用部署的工具,能帮助您便捷地管理函数计算、API ...
Python+OpenCV实时图像处理
目录 1、导入库文件 2、设计GUI 3、调用摄像头 4、实时图像处理 4.1、阈值二值化 4.2、边缘检测 4.3、轮廓检测 4.4、高斯滤波 4.5、色彩转换 4.6、调节对比度 5、退出系统 初学OpenCV图像处理的小伙伴肯定对什么高斯函数、滤波处理、阈值二值化等特性非常头疼,这里给各位分享一个小项目,可通过摄像头实时动态查看各类图像处理的特点,也可对各位调参、测试...
2020年一线城市程序员工资大调查
人才需求 一线城市共发布岗位38115个,招聘120827人。 其中 beijing 22805 guangzhou 25081 shanghai 39614 shenzhen 33327 工资分布 2020年中国一线城市程序员的平均工资为16285元,工资中位数为14583元,其中95%的人的工资位于5000到20000元之间。 和往年数据比较: yea...
为什么猝死的都是程序员,基本上不见产品经理猝死呢?
相信大家时不时听到程序员猝死的消息,但是基本上听不到产品经理猝死的消息,这是为什么呢? 我们先百度搜一下:程序员猝死,出现将近700多万条搜索结果: 搜索一下:产品经理猝死,只有400万条的搜索结果,从搜索结果数量上来看,程序员猝死的搜索结果就比产品经理猝死的搜索结果高了一倍,而且从下图可以看到,首页里面的五条搜索结果,其实只有两条才是符合条件。 所以程序员猝死的概率真的比产品经理大,并不是错...
害怕面试被问HashMap?这一篇就搞定了!
声明:本文以jdk1.8为主! 搞定HashMap 作为一个Java从业者,面试的时候肯定会被问到过HashMap,因为对于HashMap来说,可以说是Java集合中的精髓了,如果你觉得自己对它掌握的还不够好,我想今天这篇文章会非常适合你,至少,看了今天这篇文章,以后不怕面试被问HashMap了 其实在我学习HashMap的过程中,我个人觉得HashMap还是挺复杂的,如果真的想把它搞得明明白...
毕业5年,我问遍了身边的大佬,总结了他们的学习方法
我问了身边10个大佬,总结了他们的学习方法,原来成功都是有迹可循的。
推荐10个堪称神器的学习网站
每天都会收到很多读者的私信,问我:“二哥,有什么推荐的学习网站吗?最近很浮躁,手头的一些网站都看烦了,想看看二哥这里有什么新鲜货。” 今天一早做了个恶梦,梦到被老板辞退了。虽然说在我们公司,只有我辞退老板的份,没有老板辞退我这一说,但是还是被吓得 4 点多都起来了。(主要是因为我掌握着公司所有的核心源码,哈哈哈) 既然 4 点多起来,就得好好利用起来。于是我就挑选了 10 个堪称神器的学习网站,推...
这些软件太强了,Windows必装!尤其程序员!
Windows可谓是大多数人的生产力工具,集娱乐办公于一体,虽然在程序员这个群体中都说苹果是信仰,但是大部分不都是从Windows过来的,而且现在依然有很多的程序员用Windows。 所以,今天我就把我私藏的Windows必装的软件分享给大家,如果有一个你没有用过甚至没有听过,那你就赚了????,这可都是提升你幸福感的高效率生产力工具哦! 走起!???? NO、1 ScreenToGif 屏幕,摄像头和白板...
阿里面试,面试官没想到一个ArrayList,我都能跟他扯半小时
我是真的没想到,面试官会这样问我ArrayList。
曾经优秀的人,怎么就突然不优秀了。
职场上有很多辛酸事,很多合伙人出局的故事,很多技术骨干被裁员的故事。说来模板都类似,曾经是名校毕业,曾经是优秀员工,曾经被领导表扬,曾经业绩突出,然而突然有一天,因为种种原因,被裁员了,...
大学四年因为知道了这32个网站,我成了别人眼中的大神!
依稀记得,毕业那天,我们导员发给我毕业证的时候对我说“你可是咱们系的风云人物啊”,哎呀,别提当时多开心啦????,嗯,我们导员是所有导员中最帅的一个,真的???? 不过,导员说的是实话,很多人都叫我大神的,为啥,因为我知道这32个网站啊,你说强不强????,这次是绝对的干货,看好啦,走起来! PS:每个网站都是学计算机混互联网必须知道的,真的牛杯,我就不过多介绍了,大家自行探索,觉得没用的,尽管留言吐槽吧???? 社...
良心推荐,我珍藏的一些Chrome插件
上次搬家的时候,发了一个朋友圈,附带的照片中不小心暴露了自己的 Chrome 浏览器插件之多,于是就有小伙伴评论说分享一下我觉得还不错的浏览器插件。 我下面就把我日常工作和学习中经常用到的一些 Chrome 浏览器插件分享给大家,随便一个都能提高你的“生活品质”和工作效率。 Markdown Here Markdown Here 可以让你更愉快的写邮件,由于支持 Markdown 直接转电子邮...
看完这篇HTTP,跟面试官扯皮就没问题了
我是一名程序员,我的主要编程语言是 Java,我更是一名 Web 开发人员,所以我必须要了解 HTTP,所以本篇文章就来带你从 HTTP 入门到进阶,看完让你有一种恍然大悟、醍醐灌顶的感觉。 最初在有网络之前,我们的电脑都是单机的,单机系统是孤立的,我还记得 05 年前那会儿家里有个电脑,想打电脑游戏还得两个人在一个电脑上玩儿,及其不方便。我就想为什么家里人不让上网,我的同学 xxx 家里有网,每...
史上最全的IDEA快捷键总结
现在Idea成了主流开发工具,这篇博客对其使用的快捷键做了总结,希望对大家的开发工作有所帮助。
阿里程序员写了一个新手都写不出的低级bug,被骂惨了。
这种新手都不会范的错,居然被一个工作好几年的小伙子写出来,差点被当场开除了。
谁是华为扫地僧?
是的,华为也有扫地僧!2020年2月11-12日,“养在深闺人不知”的华为2012实验室扫地僧们,将在华为开发者大会2020(Cloud)上,和大家见面。到时,你可以和扫地僧们,吃一个洋...
Idea 中最常用的10款插件(提高开发效率),一定要学会使用!
学习使用一些插件,可以提高开发效率。对于我们开发人员很有帮助。这篇博客介绍了开发中使用的插件。
AI 没让人类失业,搞 AI 的人先失业了
最近和几个 AI 领域的大佬闲聊 根据他们讲的消息和段子 改编出下面这个故事 如有雷同 都是巧合 1. 老王创业失败,被限制高消费 “这里写我跑路的消息实在太夸张了。” 王葱葱哼笑一下,把消息分享给群里。 阿杰也看了消息,笑了笑。在座几位也都笑了。 王葱葱是个有名的人物,21岁那年以全额奖学金进入 KMU 攻读人工智能博士,累计发表论文 40 余篇,个人技术博客更是成为深度学习领域内风向标。 ...
立即提问