Java 获取 web 项目中的各种路径

request.getSession().getServletContext().getRealPath("/uploadfile/article");  得到保存目录的真实路径request.getServletContext().getRealPath("/")   类似上面,获取项目所在服务器的全路径,如:D:\Program Files\apache-tomcat-7.0.25\webapps\TestSytem\request.getServletPath()     获取客户端请求的路径名,如:/object/delObject    就是除域名主体额外的部分request.getContextPath()  虚拟目录request.getSession().getServletContext().getContextPath()   也可以获得虚拟目录request.getServerName()     获取服务器地址,如:localhost request.getServerPort()     获取服务器端口,如 8080request.getContextPath()     获取项目名称,如:TestSytemrequest.getLocalAddr()     获取本地地址,如:127.0.0.1request.getLocalName()     获取本地 IP 映射名,如:localhostrequest.getLocalPort()     获取本地端口,如:8090request.getRealPath("/")     获取项目所在服务器的全路径,如:D:\Program Files\apache-tomcat-7.0.25\webapps\TestSytem\request.getRemoteAddr()     获取远程主机地址,如:127.0.0.1request.getRemoteHost()     获取远程主机,如:127.0.0.1request.getRemotePort()     获取远程客户端端口,如:3623request.getRequestedSessionId()     获取会话 session 的 ID,如:823A6BACAC64FB114235CBFE85A46CAArequest.getRequestURI()     获取包含项目名称的请求路径,如:/TestSytem/object/delObjectrequest.getRequestURL().toString()     获取请求的全路径,如:http://localhost:8090/TestSytem/object/delObject

Java 获取访问请求的参数列表信息

所需依赖:servlet-api    @RequestMapping("/getPost")    public String getJson(HttpServletRequest request) throws IOException {        String sret = null;        String ContentType = "";        ContentType = request.getHeader("Content-Type");        if (ContentType.equalsIgnoreCase("application/x-www-form-urlencoded")) {//             这里 Map 中的泛型最好写上   方便 idea 自动生成 entries            Map<String, String[]> params = request.getParameterMap();//            Set 泛型写上才可以遍历 entries            Set<Map.Entry<String, String[]>> entries = params.entrySet();            String queryString = "";            for (String key : params.keySet()) {                String[] values = params.get(key);                for (int i = 0; i < values.length; i++) {                    String value = values[i];                    queryString += key + "=" + value + "&";                }            }            if (queryString.length() > 1) {                //  去掉最后一个空格                queryString = queryString.substring(0, queryString.length() - 1);            }            sret = queryString;        } else if (ContentType.equalsIgnoreCase("multipart/form-data")) {            try {                StringBuffer info = new StringBuffer();                ServletInputStream in = request.getInputStream();                BufferedInputStream buf = new BufferedInputStream(in);                byte[] buffer = new byte[1024];                int iRead;                while ((iRead = buf.read(buffer)) != -1) {                    info.append(new String(buffer, 0, iRead, "UTF-8"));                    sret = info.toString();                }            } catch (UnsupportedEncodingException e) {                // TODO Auto-generated catch block                e.printStackTrace();            } catch (IOException e) {                // TODO Auto-generated catch block                e.printStackTrace();            }        } else {        }        return sret;    }    @RequestMapping("/get")    public static String getGetParam(HttpServletRequest request) {        String sret = null;        String queryString = null;// 只能获取 get 参数        queryString = request.getQueryString();        sret = queryString;        return sret;    }

免费在线抠图 在线 P 图 免费证件照制作

remove.bg 中文:点击进入在线抠图 阿里巴巴的需要淘宝号登陆才可使用,否则会提示图片上传失败:阿里巴巴在线抠图 当然扣好图也方便做证件照了

Java 使用 Chrome 驱动作爬虫以及示例

开始准备 Chromechromedriver 驱动( 下载不同版本浏览器对应驱动教程 ) 代码pom 依赖:<dependencies>    <!-- 添加浏览器驱动 -->    <dependency>        <groupId>org.seleniumhq.selenium</groupId>        <artifactId>selenium-server</artifactId>        <version>3.141.59</version>    </dependency>    <dependency>        <groupId>cn.hutool</groupId>        <artifactId>hutool-all</artifactId>        <version>4.5.6</version>    </dependency></dependencies>Main 代码:import cn.hutool.core.date.DateUtil;import cn.hutool.core.lang.Console;import cn.hutool.core.util.StrUtil;import org.openqa.selenium.By;import org.openqa.selenium.WebDriver;import org.openqa.selenium.WebElement;import org.openqa.selenium.chrome.ChromeDriverService;import org.openqa.selenium.remote.DesiredCapabilities;import org.openqa.selenium.remote.RemoteWebDriver;import java.io.File;import java.io.IOException;import java.util.ArrayList;public class LagouSpider {    private static ArrayList<String> strings = new ArrayList<>();    public static void main(String[] args) {        String webDriverPath = LagouSpider.class.getResource("chromedriver.exe").getPath();        //  这里需要注意一定要和打开的 Chrome 版本匹配        System.setProperty("webdriver.chrome.driver", webDriverPath);        //  构建驱动        ChromeDriverService service = new ChromeDriverService.Builder().                usingDriverExecutable(new File(webDriverPath)).usingAnyFreePort().build();        try {            service.start();        } catch (IOException e) {            e.printStackTrace();        }        //  获取 Web 驱动        WebDriver driver = new RemoteWebDriver(service.getUrl(), DesiredCapabilities.chrome());        String url = "https://tophub.today/";        //  访问页面        driver.get(url);        for (int i = 0; i < 200; i++) {            for (int j = 0; j <= 10; j++) {                try {                    run(driver, webDriverPath, url, i, j);                } catch (Exception e) {                    continue;                }            }        }        Console.log(strings);        //  退出驱动线程        driver.quit();        //  关闭 service 服务        service.stop();    }    public static void run(WebDriver driver, String webDriverPath, String url, int i, int j) {        String titleExpression =                "//div[@id='node-" + i + "']/div/div[contains(@class, 'cc-cd-ih')]/div[contains(@class, 'cc-cd-is')]/a/div[contains(@class, 'cc-cd-lb')]";        String contentExpression =                "//div[@id='node-" + i + "']/div/div[contains(@class, 'cc-cd-cb nano has-scrollbar')]/div[contains(@class, 'cc-cd-cb-l nano-content')]/a[" + j + "]/div[contains(@class, 'cc-cd-cb-ll')]/span[contains(@class, 't')]";        //  获取标题        WebElement titleElement = driver.findElement(By.xpath(titleExpression));        String titleElementText = titleElement.getText();        if (StrUtil.isNotEmpty(titleElementText)) {            boolean hasStr = -1 == strings.indexOf(titleElementText);            if (hasStr) {                strings.add(titleElementText);                Console.log(StrUtil.format("[{}]",                        titleElementText));            }            WebElement textChildEle = driver.findElement(By.xpath(contentExpression));            if (StrUtil.isNotEmpty(textChildEle.getText())) {                Console.log(StrUtil.format("\t[{}]\t[{}]({})",                        DateUtil.now(),                        textChildEle.getText()),                        textChildEle.findElement(By.xpath("//div[@id='node-" + i + "']/div/div[contains(@class, 'cc-cd-cb nano has-scrollbar')]/div[contains(@class, 'cc-cd-cb-l nano-content')]/a[" + j + "]")).getAttribute("href"));            }            /*try {                Thread.sleep(1000L);            } catch (InterruptedException e) {                Console.error("Thread sleep Error");            }*/        }        //  获取内容列表        /*List<WebElement> textParentEle = driver.findElements(By.xpath(contentExpression));        for (WebElement textChildEle : textParentEle) {            WebElement childEleElement = textChildEle.findElement(By.className("t"));            boolean isEmptyForText = StrUtil.isEmpty(childEleElement.getText());            if (isEmptyForText) {                continue;            }            Console.log(StrUtil.format("\t[{}]\t[{}]\r\n",                    DateUtil.now(),                    textChildEle.getText()));        }*/    }}其中相关于 XPath 知识请 进入查看 Xpath 相关:https://blog.csdn.net/u011541946/article/details/73323911https://blog.csdn.net/u011541946/article/details/67639423

油猴 tampermonkey 谷歌插件下载与安装

1、安装谷歌 Chrome 浏览器 2、安装谷歌访问助手链接:https://pan.baidu.com/s/1oYSZijMJ7Xp5bdrrbRXNWA      提取码:fw33 3、在谷歌浏览器自带的插件商城里搜索 tampermonkey 安装即可 手机上可以下载火狐浏览器,在附加组件里找到 tampermonkey 安装即可,安装油猴脚本同上。油猴的官网:https://www.tampermonkey.net/ 油猴脚本下载:https://greasyfork.org/zh-CN/scripts

阿里巴巴免费商业普惠字体下载分享

     在 UCAN 2019 设计大会上,阿里巴巴对外发布了一款全新免费字体——阿里巴巴普惠体,并表示:“希望阿里巴巴的普惠精神,可以让整个生态的设计师、合作伙伴因为我们平台的赋能,真正得到实惠”。 据官方介绍,阿里巴巴普惠体是一款由中国企业首发,可面向全场景使用的免费商用征文字体。目前,该字体共收录 116895 个全形汉字(含 5 个字重)、7205 个拉丁字母(2 种风格、共 11 个字重)、并覆盖 172 个语种,以满足阿里巴巴集团及其经济体公司在多个场景下的使用需求。 链接:https://pan.baidu.com/s/1LhJ6v25Pvfn25EwDXcs4hg 提取码:ukgs  也可以至官网下载:https://alibabafont.taobao.com/

配置 Maven 项目中的编码

1.数据库 url=jdbc:mysql:///day17?characterEncoding=utf-82. 依次点击 File -> Settings -> Editor -> File Encodings 3. 修改maven  -Dfile.encoding=gbk4.pom.xml

配置 Maven 项目中的编码

jetbrains 系列 IDEA 等软件汉化(支持旗下 15 款软件)

下载:https://www.lanzoux.com/i3m1ipe支持所有 jetbrains 旗下软件,包括 IDEA,PyCharm,PHP 等。WIN7   WIN10 汉化:jar 文件就是汉化包,把文件直接放到目录下的 lib(是 lib 文件夹 不是 bin 文件夹) 文件夹里即可完美汉化。-----------------------------------------------------------------------------------------------mac 汉化:经过提交官网优化,已经完美支持打开设置,并支持 mac 系统。  1. 右键点击 PyCharm,选择显示包内容。 2. 选择如下路径 /Applications/PyCharm.app/Contents/lib  3. 将下载的 resources_cn.jar 复制进去 4. 将之前的 resources_en.jar 改成其他名字。

jetbrains 系列 IDEA 等软件汉化(支持旗下 15 款软件)