servlet问题,请各位帮我看看100

salana 2008-07-16 08:13:10
我在servlet-->>action方法里面创建一个对象,可这个对象就是不能调用其自身的方法,为什么?代码如下

public void actionQueryList(HttpServletRequest request,
HttpServletResponse response) throws Exception {
try {


com.mail.readxml rds=new com.mail.readxml();
String mailto=rds.index1;
System.out.println(mailto);
}}


readxml.java代码如下
public class readxml{
public static String aa="sdafd";
public static String index1=null;
public static String index2=null;
public static String index3=null;
public static String index4=null;
public static String index5=null;
public static String index6=null;
public readxml() {


Properties la = new Properties();
try {
FileInputStream file = new FileInputStream("D:/workspace/modernserver/WebRoot/WEB-INF/classes/mail.properties");
la.load(file);
String index01 = la.getProperty("index01");
String index02 = la.getProperty("index02");
String index03 = la.getProperty("index03");
String index04 = la.getProperty("index04");
String index05 = la.getProperty("index05");
String index06 = la.getProperty("index06");

this.index1=index01;
this.index2=index02;
this.index3=index03;
this.index4=index04;
this.index5=index05;
this.index6=index06;
} catch (Exception ex) {System.out.println(ex);

}

}
}
...全文
192 23 打赏 收藏 转发到动态 举报
写回复
用AI写文章
23 条回复
切换为时间正序
请发表友善的回复…
发表回复
zhj92lxs 2008-07-17
  • 打赏
  • 举报
回复
good
laorer 2008-07-17
  • 打赏
  • 举报
回复
[Quote=引用 15 楼 java2000_net 的回复:]
1 你的代码能编译吗?
我猜能,否则你不会来问了

2 你的数据能拿到吗?
我猜不能,肯定是null,否则也不来问了

3 你的代码报异常了吗?
1)报了
} catch (Exception ex) {
System.out.println(ex);
}
那就把你的异常信息贴上来

2) 没有,那就把你的 properties 文件贴上来



[/Quote]

严谨的思维,大家学学
bootupnow 2008-07-17
  • 打赏
  • 举报
回复
[Quote=引用 18 楼 salana 的回复:]
调出来了,我也不知道怎么回事就调出来了.真是对不起大家.
[/Quote]
lz看来好补习下java基础了,基础才是硬道理 ^0^
可以结贴了。
salana 2008-07-17
  • 打赏
  • 举报
回复
mail.properties文件内容如下

index01=tsshanlina@162.com
index02=shanln@6ren.com.cn
index03=shanln@6ren.com.cn
index04=shanln@6ren.com.cn
index05=shanln@6ren.com.cn
index06=shanln@6ren.com.cn
salana 2008-07-17
  • 打赏
  • 举报
回复
调出来了,我也不知道怎么回事就调出来了.真是对不起大家.
youjianbo_han_87 2008-07-17
  • 打赏
  • 举报
回复
贴出來,否则怎么看,就这么点破问题,惊动了这么多CSDNer,奇怪
bootupnow 2008-07-17
  • 打赏
  • 举报
回复
[Quote=引用 15 楼 java2000_net 的回复:]
1 你的代码能编译吗?
我猜能,否则你不会来问了

2 你的数据能拿到吗?
我猜不能,肯定是null,否则也不来问了

3 你的代码报异常了吗?
1)报了
} catch (Exception ex) {
System.out.println(ex);
}
那就把你的异常信息贴上来

2) 没有,那就把你的 properties 文件贴上来
[/Quote]
[img=http://p.blog.csdn.net/images/p_blog_csdn_net/bootupnow/428259/o_dog1.gif]pic[/img]
老紫竹 2008-07-17
  • 打赏
  • 举报
回复
1 你的代码能编译吗?
我猜能,否则你不会来问了

2 你的数据能拿到吗?
我猜不能,肯定是null,否则也不来问了

3 你的代码报异常了吗?
1)报了
} catch (Exception ex) {
System.out.println(ex);
}
那就把你的异常信息贴上来

2) 没有,那就把你的 properties 文件贴上来



qfs_v 2008-07-17
  • 打赏
  • 举报
回复
java基础不牢固,你这样学习servlet是事倍功半!
happystarting 2008-07-17
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 imA 的回复:]
你的index1、index2等属性定义都是static,当然不能用this引用了,将static修饰符去掉
[/Quote]
shoushii 2008-07-16
  • 打赏
  • 举报
回复
如何获得la对象中的所有的键例如:index1 和所有的值,能获得la对象所有元素的个数吗?
可以通过索引的方式获得其中的值吗? la.getProperty(0);

shoushii 2008-07-16
  • 打赏
  • 举报
回复
请问可以通过什么方式访问la对象里的所有元素?
KOOK_OKKO 2008-07-16
  • 打赏
  • 举报
回复
/mail.properties这里面怎么写的
bootupnow 2008-07-16
  • 打赏
  • 举报
回复
[Quote=引用 9 楼 bootupnow 的回复:]
引用 6 楼 interpb 的回复:
会啊 构造函数里面只要不抛出异常 就会用资源文件里的值赋给 index

你运行有异常了吗

lz异常了^0^,忘记了他没import
[/Quote]
可没法编译呀,再晕
bootupnow 2008-07-16
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 interpb 的回复:]
会啊 构造函数里面只要不抛出异常 就会用资源文件里的值赋给 index

你运行有异常了吗
[/Quote]
lz异常了^0^,忘记了他没import
interpb 2008-07-16
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 imA 的回复:]
你的index1、index2等属性定义都是static,当然不能用this引用了,将static修饰符去掉
[/Quote]

这不是问题所在吧

虽然不建议用对象引用静态属性 但不会出错的
bootupnow 2008-07-16
  • 打赏
  • 举报
回复
this.index1=index01; // 这里你不是赋值了么?

String index01 = la.getProperty("index01"); // 当然,还要看你从文件mail.properties取到值没有
interpb 2008-07-16
  • 打赏
  • 举报
回复
会啊 构造函数里面只要不抛出异常 就会用资源文件里的值赋给 index

你运行有异常了吗
imA 2008-07-16
  • 打赏
  • 举报
回复
你的index1、index2等属性定义都是static,当然不能用this引用了,将static修饰符去掉
salana 2008-07-16
  • 打赏
  • 举报
回复
public class readxml{ 
public static String aa="sdafd";
public static String index1=null;
public static String index2=null;
public static String index3=null;
public static String index4=null;
public static String index5=null;
public static String index6=null;
public readxml() {


Properties la = new Properties();
try {
FileInputStream file = new FileInputStream("D:/workspace/modernserver/WebRoot/WEB-INF/classes/mail.properties");
la.load(file);
String index01 = la.getProperty("index01");
String index02 = la.getProperty("index02");
String index03 = la.getProperty("index03");
String index04 = la.getProperty("index04");
String index05 = la.getProperty("index05");
String index06 = la.getProperty("index06");

this.index1=index01;
this.index2=index02;
this.index3=index03;
this.index4=index04;
this.index5=index05;
this.index6=index06;
} catch (Exception ex) {System.out.println(ex);

}

}
}


就是我这个类在生成对象的时候index1会不会被附值?
加载更多回复(2)

67,538

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧