dwr实现ajax
getTypeList()方法供ajax调用,可是得不到request,执行时页面上就弹出一个alert,上面只显示ERROR
要怎么得到requestpublic class FileUploadAction extends ActionSupport {
public HttpServletRequest request;
public String dburl; public List getTypeList() {
System.out.println(1);//这句能打印,然后就啥都没了
request = ServletActionContext.getRequest();//走到这就停了
System.out.println(2);
dburl = request.getSession().getServletContext().getRealPath("/"); return null;
}
}
getTypeList()方法供ajax调用,可是得不到request,执行时页面上就弹出一个alert,上面只显示ERROR
要怎么得到requestpublic class FileUploadAction extends ActionSupport {
public HttpServletRequest request;
public String dburl; public List getTypeList() {
System.out.println(1);//这句能打印,然后就啥都没了
request = ServletActionContext.getRequest();//走到这就停了
System.out.println(2);
dburl = request.getSession().getServletContext().getRealPath("/"); return null;
}
}
解决方案 »
- j2ee首页如何生成静态页面
- hibernate annotation hql如何多表查询
- hibernate 问题
- JPA开发,报错:java.lang.NoClassDefFoundError: javax/persistence/spi/ProviderUtil
- 关于xfire的问题
- java连SQL2005的jar包 是不是这个
- CMP中查询问题。
- easy struts开发的问题
- ? 为什么我在Eclipse2.1使用InitialContext来实现JNDI出现问题呢? 在线等待。
- Spring嵌套事务问题
- Hibernate session线程安全问题
- Win7系统下安装Jprofiler时报错
pw.write("需返回的数据")
WebContext webContext = WebContextFactory.get();
HttpSession session = webContext.getSession();
HttpServletRequest request=webContext.getHttpServletRequest();
HttpServletResponse response=webContext.getHttpServletResponse();
我要在java方法里得到request,因为要得到路径,这个路径java方法里要用
检查一下你的配置吧,你的request应该是个null,所以执行
dburl = request.getSession().getServletContext().getRealPath("/");
这句时,会报空指针吧?最好把错误贴出来
错误就是一个alert上显示ERROR,没提示别的
public HttpServletRequest request;
public String dburl; public String getTypeList() throws Exception{
System.out.println(1);//这句能打印,然后就啥都没了
request = ServletActionContext.getRequest();//走到这就停了
System.out.println(2);
dburl = request.getSession().getServletContext().getRealPath("/"); return null;
}
}不可能啊 获取requeset肯定所没问题的
可我这确实出错啊,我都重建工程了,重新写了这段,打开http://localhost:8080/工程/dwr,用dwr测试i,也不行啊
===>>
public List getTypeList(HttpServletRequest request){
//do what you want to...
}
不点击进入方法呢?
request = ServletActionContext.getRequest();肯定是这有问题
把页面的alert去掉跟踪一下这段代码,看看获取的request到底是什么东西
private HttpServletRequest request;
public void setServletRequest(HttpServletRequest request)
{
this.request = request;
}
这样就ok了,response也一样,实现的接口不一样而已。