「authjava源码」java auth
本篇文章给大家谈谈authjava源码,以及java auth对应的知识点,希望对各位有所帮助,不要忘了收藏本站喔。
本文目录一览:
- 1、怎样用Java实现 判断插入的authUserLogin是否与数据库表auth中的同名,若同名返回false,新手求指点
- 2、关于sun.misc.BASE64Encoder的问题
- 3、我在CentOS系统中配置hadoopp,在eclipse中运行hadoopp的wordcount.java源代码
- 4、求一个javaweb邮件收发系统eclipse源代码,tomcat可以运行的。
怎样用Java实现 判断插入的authUserLogin是否与数据库表auth中的同名,若同名返回false,新手求指点
怎样用Java实现 判断插入的authUserLogin是否与数据库表auth中的同名,若同名返回false,代码如下:
用户名input type = "text" id="username" onBlur="post()"
jquery+ajax:
function post() {
alert($("#username").val());
$.ajax({
type:"POST",
url:"user.action",//后台注册方法,包含校验或者直接校验,按照自己的来
data: "user.name=" +$("#username").val(),
dataType: "html" ,
success:callback //回调函数
}) ;
}
function callback(data) {
var a = parseInt(data);
if(a == 0) {
alert("注册成功");
}
else if(a==1) {
alert("该用户名已经存在");
}
大概可以写成这样。。。哦了不
关于sun.misc.BASE64Encoder的问题
BASE64Encoder和Decoder是非官方JDK里面的类。虽然可以在JDK里能找到并使用,但是在API里查不到。这两个可能是SUN公司内部人使用的,我们使用后出了问题也就不能责怪SUN。据我所知SUN开头的包里面的类都找不到相关文档,所以里面可能都是非官方的类。出现警告也是非常合理和正常的,因为以后SUN可能会更新或这删除那些非官方的类。不用管它。
我在CentOS系统中配置hadoopp,在eclipse中运行hadoopp的wordcount.java源代码
新建一个hadoop工程,如图
建一个运行wordcount的类,先不管他什么意思,代码如下
[java] view plain copy
/**
* Project: hadoop
*
* File Created at 2012-5-21
* $Id$
*/
package seee.you.app;
import java.io.IOException;
import java.util.StringTokenizer;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.Mapper;
import org.apache.hadoop.mapreduce.Reducer;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
public class WordCount {
public static class TokenizerMapper extends MapperLongWritable, Text, Text, IntWritable{
private final static IntWritable one = new IntWritable(1);
private Text word = new Text();
public void map(LongWritable key, Text value, Context context)
throws IOException, InterruptedException {
StringTokenizer itr = new StringTokenizer(value.toString());
while (itr.hasMoreTokens()) {
word.set(itr.nextToken());
context.write(word, one);
}
}
}
public static class IntSumReducer extends ReducerText, IntWritable, Text, IntWritable {
private IntWritable result = new IntWritable();
public void reduce(Text key, IterableIntWritable values, Context context)
throws IOException, InterruptedException {
int sum = 0;
for (IntWritable val : values) {
sum += val.get();
}
result.set(sum);
context.write(key, result);
}
}
public static void main(String[] args) throws Exception {
Configuration conf = new Configuration();
if (args.length != 2) {
System.err.println("Usage: wordcount ");
System.exit(2);
}
Job job = new Job(conf, "word count");
job.setJarByClass(WordCount.class);
job.setMapperClass(TokenizerMapper.class);
job.setReducerClass(IntSumReducer.class);
job.setMapOutputKeyClass(Text.class);
job.setMapOutputValueClass(IntWritable.class);
job.setOutputKeyClass(Text.class);
job.setOutputValueClass(IntWritable.class);
FileInputFormat.addInputPath(job, new Path(args[0]));
FileOutputFormat.setOutputPath(job, new Path(args[1]));
System.exit(job.waitForCompletion(true) ? 0 : 1);
}
}
这时候右键run on hadoop
这时候不幸的是,报错了,错误信息如下:
[java] view plain copy
12/05/23 19:38:51 WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
12/05/23 19:38:51 ERROR security.UserGroupInformation: PriviledgedActionException as:yongkang.qiyk cause:java.io.IOException: Failed to set permissions of path: \tmp\hadoop-yongkang\mapred\staging\yongkang.qiyk-1840800210\.staging to 0700
Exception in thread "main" java.io.IOException: Failed to set permissions of path: \tmp\hadoop-yongkang\mapred\staging\yongkang.qiyk-1840800210\.staging to 0700
at org.apache.hadoop.fs.FileUtil.checkReturnValue(FileUtil.java:682)
at org.apache.hadoop.fs.FileUtil.setPermission(FileUtil.java:655)
at org.apache.hadoop.fs.RawLocalFileSystem.setPermission(RawLocalFileSystem.java:509)
at org.apache.hadoop.fs.RawLocalFileSystem.mkdirs(RawLocalFileSystem.java:344)
at org.apache.hadoop.fs.FilterFileSystem.mkdirs(FilterFileSystem.java:189)
at org.apache.hadoop.mapreduce.JobSubmissionFiles.getStagingDir(JobSubmissionFiles.java:116)
at org.apache.hadoop.mapred.JobClient$2.run(JobClient.java:856)
at org.apache.hadoop.mapred.JobClient$2.run(JobClient.java:850)
at java.security.AccessController.doPrivileged(Native Method)
at javax.security.auth.Subject.doAs(Subject.java:396)
at org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1093)
at org.apache.hadoop.mapred.JobClient.submitJobInternal(JobClient.java:850)
at org.apache.hadoop.mapreduce.Job.submit(Job.java:500)
at org.apache.hadoop.mapreduce.Job.waitForCompletion(Job.java:530)
at seee.you.app.WordCount.main(WordCount.java:80)
错误信息很明显了,at org.apache.hadoop.fs.FileUtil.checkReturnValue(FileUtil.java:682) 这一行的方法报错了
网上查到这是由于0.20.203.0以后的版本的权限认证引起的,只有去掉才行
修改hadoop源代码,去除权限认证,修改FileUtil.java的checkReturnValue方法,如下:
[java] view plain copy
private static void checkReturnValue(boolean rv, File p,
FsPermission permission
) throws IOException {
// if (!rv) {
// throw new IOException("Failed to set permissions of path: " + p +
// " to " +
// String.format("%04o", permission.toShort()));
// }
}
去掉这一行后,需要重新编译打包下,打包成功之后,可以将hadoop-core-1.0.2.jar拷贝到hadoop根目录下,eclipse中重新导入下即可(我用的这个1.0.2是从网上下载的修改好的,比较省事)
这时重新运行下实例,运行实例需要配置下arguments参数,我的配置如下:
run一下,结果如下,说明已经成功了
[java] view plain copy
WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
WARN mapred.JobClient: Use GenericOptionsParser for parsing the arguments. Applications should implement Tool for the same.
****hdfs://10.16.110.7:9000/user/yongkang/test-in
INFO input.FileInputFormat: Total input paths to process : 0
INFO mapred.JobClient: Running job: job_local_0001
INFO mapred.Task: Using ResourceCalculatorPlugin : null
INFO mapred.LocalJobRunner:
INFO mapred.Merger: Merging 0 sorted segments
INFO mapred.Merger: Down to the last merge-pass, with 0 segments left of total size: 0 bytes
INFO mapred.LocalJobRunner:
INFO mapred.Task: Task:attempt_local_0001_r_000000_0 is done. And is in the process of commiting
INFO mapred.LocalJobRunner:
INFO mapred.Task: Task attempt_local_0001_r_000000_0 is allowed to commit now
INFO output.FileOutputCommitter: Saved output of task 'attempt_local_0001_r_000000_0' to /user/yongkang/test-out6
INFO mapred.JobClient: map 0% reduce 0%
INFO mapred.LocalJobRunner: reduce reduce
INFO mapred.Task: Task 'attempt_local_0001_r_000000_0' done.
INFO mapred.JobClient: map 0% reduce 100%
INFO mapred.JobClient: Job complete: job_local_0001
INFO mapred.JobClient: Counters: 10
INFO mapred.JobClient: File Output Format Counters
INFO mapred.JobClient: Bytes Written=0
INFO mapred.JobClient: FileSystemCounters
INFO mapred.JobClient: FILE_BYTES_READ=8604
INFO mapred.JobClient: FILE_BYTES_WRITTEN=51882
INFO mapred.JobClient: Map-Reduce Framework
INFO mapred.JobClient: Reduce input groups=0
INFO mapred.JobClient: Combine output records=0
INFO mapred.JobClient: Reduce shuffle bytes=0
INFO mapred.JobClient: Reduce output records=0
INFO mapred.JobClient: Spilled Records=0
INFO mapred.JobClient: Total committed heap usage (bytes)=5177344
INFO mapred.JobClient: Reduce input records=0
求一个javaweb邮件收发系统eclipse源代码,tomcat可以运行的。
package me.gacl.main;
import java.util.Properties;
import javax.mail.Message;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
public class Sendmail {
/**
* @param args
* @throws Exception
*/
public static void main(String[] args) throws Exception {
Properties prop = new Properties();
prop.setProperty("mail.host", "smtp.sohu.com");
prop.setProperty("mail.transport.protocol", "smtp");
prop.setProperty("mail.smtp.auth", "true");
//使用JavaMail发送邮件的5个步骤
//1、创建session
Session session = Session.getInstance(prop);
//开启Session的debug模式,这样就可以查看到程序发送Email的运行状态
session.setDebug(true);
//2、通过session得到transport对象
Transport ts = session.getTransport();
//3、使用邮箱的用户名和密码连上邮件服务器,发送邮件时,发件人需要提交邮箱的用户名和密码给smtp服务器,用户名和密码都通过验证之后才能够正常发送邮件给收件人。
ts.connect("smtp.sohu.com", "gacl", "邮箱密码");
//4、创建邮件
Message message = createSimpleMail(session);
//5、发送邮件
ts.sendMessage(message, message.getAllRecipients());
ts.close();
}
/**
* @Method: createSimpleMail
* @Description: 创建一封只包含文本的邮件
* @param session
* @return
* @throws Exception
*/
public static MimeMessage createSimpleMail(Session session)
throws Exception {
//创建邮件对象
MimeMessage message = new MimeMessage(session);
//指明邮件的发件人
message.setFrom(new InternetAddress("gacl@sohu.com"));
//指明邮件的收件人,现在发件人和收件人是一样的,那就是自己给自己发
message.setRecipient(Message.RecipientType.TO, new InternetAddress("gacl@sohu.com"));
//邮件的标题
message.setSubject("只包含文本的简单邮件");
//邮件的文本内容
message.setContent("你好啊!", "text/html;charset=UTF-8");
//返回创建好的邮件对象
return message;
}
}
关于authjava源码和java auth的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。