package reWeb;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.util.Vector;
public class AddJavaBean {
private String id;
private String name;
private String author;
private String isbn;
private String introduction;
private int tb=8;
public int getTb(){
return this.tb;
}
public void setTb(int tb){
this.tb=tb;
}
public String getId(){
return this.id;
}
public String getName(){
return this.name;
}
public String getAuthor(){
return this.author;
}
public String getIsbn(){
return this.isbn;
}
public String getIntroduction(){
return this.introduction;
}
public void setId(String id){
this.id=id;
}
public void setName(String name){
this.name=name;
}
public void setAuthor(String author){
this.author=author;
}
public void setIsbn(String isbn){
this.isbn=isbn;
}
public void setIntroduction(String introduction){
this.introduction=introduction;
}
public void add(){
PrintWriter pw=null;
String addMessage=new String(this.id+","+this.name+","+this.author+","+this.isbn+","+this.introduction);
try{
pw = new PrintWriter(new FileOutputStream("d:\\date.txt",true));
pw.println(addMessage);
pw.flush();
pw.close();
}
catch(Exception e){
pw.close();
}
}
public void search(String str) throws IOException{
BufferedReader br=null;
String d=null;
try{
br=new BufferedReader(new InputStreamReader(new FileInputStream("d:\\date.txt")));
while((d=br.readLine())!=null){
String[] sp=d.split(",");
if(str.equals(sp[0])){
this.name=sp[1];
this.author=sp[2];
this.isbn=sp[3];
this.introduction=sp[4];
this.tb=0;
break;
}
else{this.tb=-1;}
}
br.close();
}
catch(Exception e){
br.close();
}
}
public void delete() throws IOException //每次调用delete都生成一个临时文本文件
{
File file=new File("d:\\date.txt");
File file2=null;
//try{
// File f = new File("D:" + File.separatorChar);
// f.mkdir();
//file2=File.createTempFile("ddd",".txt",f);
file2=new File("d:\\tt.txt");
// }catch(IllegalArgumentException e){
//}catch(SecurityException e){}
//catch(IOException e){} //创建一个文本文件并赋值为file2
PrintWriter pw=null;
BufferedReader br=null;
String[] astr=new String[5];
String d=null;
try {
br=new BufferedReader(new InputStreamReader(new FileInputStream(file)));
pw = new PrintWriter(new FileOutputStream(file2),true);
while((d=br.readLine())!=null){
astr=d.split(",");
if(!id.equals(astr[0])){
System.out.println(id+astr[0]);
//pw = new PrintWriter(new FileOutputStream(file2),true);
pw.println(d);
// pw.flush();
}
}
br.close();
pw.close();
}
catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
pw.close();
br.close();
}
file.delete();
file2.renameTo(file);
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
一个简单的基于MVC结构的,JSP+Servlet+JavaBean实现文本文件增删改查功能的
共26个文件
jsp:12个
java:3个
class:3个
5星 · 超过95%的资源 需积分: 9 252 下载量 154 浏览量
2009-09-16
10:48:11
上传
评论 11
收藏 16KB RAR 举报
温馨提示
刚进公司,几天后师傅教我实现一个文本的增删改查功能,要求实现MVC,可以用Servlet! 自己初学的,自己实现的,适合初学者共享!
资源推荐
资源详情
资源评论
收起资源包目录
reWeb.rar (26个子文件)
reWeb
.project 1KB
.settings
.jsdtscope 500B
org.eclipse.wst.jsdt.ui.superType.container 49B
org.eclipse.wst.jsdt.ui.superType.name 6B
.mymetadata 288B
WebRoot
view.jsp 1KB
WEB-INF
web.xml 1KB
lib
classes
reWeb
AddJavaBean.class 4KB
ActionServlet.class 2KB
UDactionServlet.class 2KB
exsit.jsp 885B
begin.jsp 737B
index.jsp 831B
META-INF
MANIFEST.MF 36B
notExsit.jsp 879B
view1.jsp 1KB
add.jsp 1KB
update.jsp 1KB
notExsit2.jsp 909B
search.jsp 747B
delete.jsp 1KB
de.jsp 936B
.myeclipse
src
reWeb
UDactionServlet.java 2KB
AddJavaBean.java 4KB
ActionServlet.java 2KB
.classpath 362B
共 26 条
- 1
budongzhd
- 粉丝: 0
- 资源: 1
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
- 3
- 4
- 5
前往页