java搜索代码 java搜索功能怎么实现流程

怎样在网上查找JAVA源代码用百度搜索一下,就用“JAVA源代码“做为搜索条件 。一般能找到很多网站 。
要学JAVA最好还是找本书看一看 。JAVA能做的东西很多,你要决定你的主攻方向然后就去找相应的资料 。
你要学哪方面:
JAVA应用程序开发,
JAVA网络开发:JSP,APPLET 。
JAVA手持设备软件开发,像手机软件等 。
如果对程序还不是很懂,最好找本JAVA入门级的书看看 , 然后再决定 。
求用java 正则表达式搜索字符串源代码类中用到了 jakarta-oro-2.0.jar包 , 请自己在 apache网站下下载
这个Java正则表达式工具类目前主要有25种正规表达式,有些不常用,这里只列出15种常用Java正则表达式功能:
1.匹配图象;
2 匹配email地址;
3 匹配匹配并提取url ;
4 匹配并提取http ;
5.匹配日期
6 匹配电话;
7 匹配身份证
8 匹配邮编代码
9. 不包括特殊字符的匹配
10 匹配非负整数(正整数0)
11 匹配不包括零的非负整数(正整数0)
12 匹配正整数
13匹配非正整数(负整数0)
14 匹配负整数;
15.匹配整数
package com.ygj.util;import java.util.*;import org.apache.oro.text.regex.*;/*** 类简介: 使用正则表达式验证数据或提取数据,类中的方法全为静态的* 主要方法:1. isHardRegexpValidate(String source, String regexp)区分大小写敏感的正规表达式批配*2. isSoftRegexpValidate(String source, String regexp)*不区分大小写的正规表达式批配*3. getHardRegexpMatchResult(String source, String regexp)*返回许要的批配结果集(大小写敏感的正规表达式批配)*4. getSoftRegexpMatchResult(String source, String regexp)*返回许要的批配结果集(不区分大小写的正规表达式批配)*5getHardRegexpArray(String source, String regexp)*返回许要的批配结果集(大小写敏感的正规表达式批配)*6. getSoftRegexpMatchResult(String source, String regexp)*返回许要的批配结果集(不区分大小写的正规表达式批配)*7.getBetweenSeparatorStr(final String originStr,final char leftSeparator,final char rightSeparator)*得到指定分隔符中间的字符串的集合** @mail wuzhi2000@hotmail.com* @author ygj**/public final class Regexp{/**保放有四组对应分隔符 */static finalSet SEPARATOR_SET=new TreeSet();{SEPARATOR_SET.add("(");SEPARATOR_SET.add(")");SEPARATOR_SET.add("[");SEPARATOR_SET.add("]");SEPARATOR_SET.add("{");SEPARATOR_SET.add("}");SEPARATOR_SET.add("");SEPARATOR_SET.add("");}/** 存放各种正规表达式(以key-value的形式) */public static HashMap regexpHash = new HashMap();/** 存放各种正规表达式(以key-value的形式) */public staticList matchingResultList = new ArrayList();privateRegexp(){}/*** 返回 Regexp 实例* @return*/public static Regexp getInstance(){return new Regexp();}/*** 匹配图象** 格式: /相对路径/文件名.后缀 (后缀为gif,dmp,png)** 匹配 : /forum/head_icon/admini2005111_ff.gif 或 admini2005111.dmp** 不匹配: c:/admins4512.gif**/public static final String icon_regexp = "^(/{0,1}\\w){1,}\\.(gif|dmp|png|jpg)$|^\\w{1,}\\.(gif|dmp|png|jpg)$";/*** 匹配email地址** 格式: XXX@XXX.XXX.XX** 匹配 : foo@bar.com 或 foobar@foobar.com.au** 不匹配: foo@bar 或 $$$@bar.com**/public static final String email_regexp = "(?:\\w[-._\\w]*\\w@\\w[-._\\w]*\\w\\.\\w{2,3}$)";/*** 匹配匹配并提取url** 格式: XXXX://XXX.XXX.XXX.XX/XXX.XXX?XXX=XXX** 匹配 :或news://www** 提取(MatchResult matchResult=matcher.getMatch()):*matchResult.group(0)=*matchResult.group(1) = http*matchResult.group(2) =*matchResult.group(3) = :8080*matchResult.group(4) = /index.html?login=true** 不匹配: c:\window**/public static final String url_regexp = "(\\w )://([^/:] )(:\\d*)?([^#\\s]*)";/*** 匹配并提取http** 格式:或或** 匹配 :** 提取(MatchResult matchResult=matcher.getMatch()):*matchResult.group(0)=*matchResult.group(1) = http*matchResult.group(2) =*matchResult.group(3) = :8080*matchResult.group(4) = /index.html?login=true** 不匹配: news://www**/public static final String http_regexp = "(http|https|ftp)://([^/:] )(:\\d*)?([^#\\s]*)";/*** 匹配日期** 格式(首位不为0): XXXX-XX-XX 或 XXXX XX XX 或 XXXX-X-X** 范围:1900--2099** 匹配 : 2005-04-04** 不匹配: 01-01-01**/public static final String date_regexp = "^((((19){1}|(20){1})d{2})|d{2})[-\\s]{1}[01]{1}d{1}[-\\s]{1}[0-3]{1}d{1}$";// 匹配日期/*** 匹配电话** 格式为: 0XXX-XXXXXX(10-13位首位必须为0) 或0XXX XXXXXXX(10-13位首位必须为0) 或* (0XXX)XXXXXXXX(11-14位首位必须为0) 或 XXXXXXXX(6-8位首位不为0) 或* XXXXXXXXXXX(11位首位不为0)** 匹配 : 0371-123456 或 (0371)1234567 或 (0371)12345678 或 010-123456 或* 010-12345678 或 12345678912** 不匹配: 1111-134355 或 0123456789**/public static final String phone_regexp = "^(?:0[0-9]{2,3}[-\\s]{1}|\\(0[0-9]{2,4}\\))[0-9]{6,8}$|^[1-9]{1}[0-9]{5,7}$|^[1-9]{1}[0-9]{10}$";/*** 匹配身份证** 格式为: XXXXXXXXXX(10位) 或 XXXXXXXXXXXXX(13位) 或 XXXXXXXXXXXXXXX(15位) 或* XXXXXXXXXXXXXXXXXX(18位)** 匹配 : 0123456789123** 不匹配: 0123456**/public static final String ID_card_regexp = "^\\d{10}|\\d{13}|\\d{15}|\\d{18}$";/*** 匹配邮编代码** 格式为: XXXXXX(6位)** 匹配 : 012345** 不匹配: 0123456**/public static final String ZIP_regexp = "^[0-9]{6}$";// 匹配邮编代码/*** 不包括特殊字符的匹配 (字符串中不包括符号 数学次方号^ 单引号' 双引号" 分号; 逗号, 帽号: 数学减号- 右尖括号 左尖括号反斜杠\ 即空格,制表符,回车符等 )** 格式为: x 或 一个一上的字符** 匹配 : 012345** 不匹配: 0123456**/public static final String non_special_char_regexp = "^[^'\"\\;,:-\\s]. $";// 匹配邮编代码/*** 匹配非负整数(正整数0)*/public static final String non_negative_integers_regexp = "^\\d $";/*** 匹配不包括零的非负整数(正整数0)*/public static final String non_zero_negative_integers_regexp = "^[1-9] \\d*$";/**** 匹配正整数**/public static final String positive_integer_regexp = "^[0-9]*[1-9][0-9]*$";/**** 匹配非正整数(负整数0)**/public static final String non_positive_integers_regexp = "^((-\\d )|(0 ))$";/**** 匹配负整数**/public static final String negative_integers_regexp = "^-[0-9]*[1-9][0-9]*$";/**** 匹配整数**/public static final String integer_regexp = "^-?\\d $";/**** 匹配非负浮点数(正浮点数0)**/public static final String non_negative_rational_numbers_regexp = "^\\d (\\.\\d )?$";/**** 匹配正浮点数**/public static final String positive_rational_numbers_regexp = "^(([0-9] \\.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*\\.[0-9] )|([0-9]*[1-9][0-9]*))$";/**** 匹配非正浮点数(负浮点数0)**/public static final String non_positive_rational_numbers_regexp = "^((-\\d (\\.\\d )?)|(0 (\\.0 )?))$";/**** 匹配负浮点数**/public static final String negative_rational_numbers_regexp = "^(-(([0-9] \\.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*\\.[0-9] )|([0-9]*[1-9][0-9]*)))$";/**** 匹配浮点数**/public static final String rational_numbers_regexp = "^(-?\\d )(\\.\\d )?$";/**** 匹配由26个英文字母组成的字符串**/public static final String letter_regexp = "^[A-Za-z] $";/**** 匹配由26个英文字母的大写组成的字符串**/public static final String upward_letter_regexp = "^[A-Z] $";/**** 匹配由26个英文字母的小写组成的字符串**/public static final String lower_letter_regexp = "^[a-z] $";/**** 匹配由数字和26个英文字母组成的字符串**/public static final String letter_number_regexp = "^[A-Za-z0-9] $";/**** 匹配由数字、26个英文字母或者下划线组成的字符串**/public static final String letter_number_underline_regexp = "^\\w $";/*** 添加正规表达式 (以key-value的形式存储)** @param regexpName*该正规表达式名称 `* @param regexp*该正规表达式内容*/public void putRegexpHash(String regexpName, String regexp){regexpHash.put(regexpName, regexp);}/*** 得到正规表达式内容 (通过key名提取出value[正规表达式内容])** @param regexpName*正规表达式名称** @return 正规表达式内容*/public String getRegexpHash(String regexpName){if (regexpHash.get(regexpName) != null){return ((String) regexpHash.get(regexpName));}else{System.out.println("在regexpHash中没有此正规表达式");return "";}}/*** 清除正规表达式存放单元*/public void clearRegexpHash(){regexpHash.clear();return;}/*** 大小写敏感的正规表达式批配** @param source*批配的源字符串** @param regexp*批配的正规表达式** @return 如果源字符串符合要求返回真,否则返回假 如:Regexp.isHardRegexpValidate("ygj@suncer.com.cn",email_regexp) 返回真*/public static boolean isHardRegexpValidate(String source, String regexp){try{// 用于定义正规表达式对象模板类型PatternCompiler compiler = new Perl5Compiler();// 正规表达式比较批配对象PatternMatcher matcher = new Perl5Matcher();// 实例大小大小写敏感的正规表达式模板Pattern hardPattern = compiler.compile(regexp);// 返回批配结果return matcher.contains(source, hardPattern);}catch (MalformedPatternException e){e.printStackTrace();}return false;}
JAVA中怎么查询代码?try{Connection con;
Statement stmt;
ResultSet rs;
int temp;
Class.forName("com.mysql.jdbc.Driver");
con=DriverManager.getConnection("jdbc:mysql://localhost:3306/java","root","");//以上是数据库连接,不同的数据管理器有//不同的驱动和链接方式,以上是mysql的连接
stmt=con.createStatement();
rs=stmt.executeQuery("select * from student");//执行查询语句,结果赋值给结果集rs
//结果集是结果于字段编号的映射,每一个字
//段都有一个编号 , 最小为1 , 也就是第一个字段
while(rs.next()){
String names=rs.getString("name");//查询结果转换成字符串 。
System.out.println(names);
}rs.close();
}catch(Exception e){
e.printStackTrace();
}
求基于JAVA设计的搜索引擎代码 。在业务逻辑层里操作不是都相同的么?为什么特别指出不需要JSP要用GUI呢?难道是用ajax写?但你说在数据库搜索内容并显示又不像ajax 。搞不懂 。
类似于下面那样子的业务吧?:
String sql="select WP_PRODUCT.*,WP_PROD_CTGRY.C_NAME from WP_PRODUCT,WP_PROD_CTGRY where WP_PRODUCT.CTGRY_ID=WP_PROD_CTGRY.TID ";
ListObject params=new ArrayListObject();
if(type!=null!"".equals(type)){
sql =" and CTGRY_ID like ?";
params.add(type "%");
}
if(proName!=null!"".equals(proName)){
sql =" and NAME like ?";
params.add("%" proName "%");
}
if(code!=null!"".equals(code)){
sql =" and CUSTOM_ID like ?";
params.add(code "%");
}
if(brandId!=null!"".equals(brandId)){
sql =" and OWNER_ID = ?";
params.add(brandId);
}
if(netId!=null!"".equals(netId)) {
sql= " and WP_PRODUCT.TIDIN(SELECT PRODUCT_ID FROM WP_NET_PRODUCT WHERE OWNER_ID = ?) ";
params.add(netId);
}
sql= " order by WP_PRODUCT.MOD_DATE desc";
this.getVisitor().createPaginationExecutor(sql, page, params.toArray()).pagination(WpProdBean.class);
通过文字搜索图片 java代码实现及说明import ja.io.*;
//获取文件夹内容
public class getthing
{
public static void main(String[] args) throws Exception
{
System.out.println(welstr);
listFile(new File("e:\\aa")); //想要搜索的路径
}
public static void listFile(File file) throws Exception
{
if(file.isFile())
{
//输出的是完整的文件夹内文件的路径
System.out.println("File :" file.getAbsolutePath());
//01.jpg就是java搜索代码你要找的图片
if (file.getAbsolutePath().endsWith("01.jpg"))
System.out.println("有搜索的图片");
}
else
{
System.out.println("Dir :" file.getAbsolutePath());
File[] files =file.listFiles();
for(int i=0;ifiles.length;i)
{
listFile(files[i]);
System.out.println("回车");
}
}
}
}
1 首先确定java搜索代码你要搜索的目录
2 要搜索的关键字 如“花”
3 只搜索图片类型 .jpg .gif .png .bmp之类的
4 在文本框里获得搜索的关键字
5 取得要搜索目录下的所有图片类型的名字
6 用关键字和取得的文件名一一进行对比
7 若有关键字 记录该图片的名字
8 若都没关键字 表示无该名字的图片
9 空白区域你可以用一个窗体来表示
10 把搜索到的图片都显示在这个窗体 。
java如何实现搜索功能 。比如,输入txt就能搜索出这个文件夹内所有txt格式的文件 。请给完整代码 。import java.io.*;
public class FileDemo{
public static void main(String[] args)throws Exception{
//第一个参数是文件路径 , 第二个参数是要搜索的文件扩展名
getFile("D:\\JavaDemo",".txt");
}
private static void getFile(String pathName, final String endsWith)throws Exception{
File file = new File(pathName);
if(!file.exists())
throw new RuntimeException("文件不存在,你检索个P呀 。");
file.listFiles(new FileFilter(){
public boolean accept(File file){
if(file.getName().endsWith(endsWith)){
System.out.println(file.getName());
return true;
}else
return false;
}
});
}
}
【java搜索代码 java搜索功能怎么实现流程】java搜索代码的介绍就聊到这里吧,感谢你花时间阅读本站内容 , 更多关于java搜索功能怎么实现流程、java搜索代码的信息别忘了在本站进行查找喔 。

    推荐阅读