使用Struts2进行开发时,经常会遇到下面这样的问题:
Struts Problem Report
Struts has detected an unhandled exception:
而问题的原因可能有很多,但是一般来说都是因为运行时遇到了不能识别的标识的错误,包括类名,路径名,方法名等,只要按照具体的错误提示内容仔细检查整个页面的运行流程涉及到的程序代码,就可以找出错误的原因了。
如下面遇到了该错误信息:
首先显示
Struts Problem Report
Struts has detected an unhandled exception:
可以发现是这类错误,然后下面继续有详细的错误提示:
Unresolved compilation problems: Question cannot be resolved to a type questions cannot be resolved
Could not instantiate bean class [com.exam.student.actions.UploadAction]:
Constructor threw exception; nested exception is java.lang.Error: Unresolved compilation problems: Question cannot be resolved to a type questions cannot be resolved
由此可以发现应该是Question相关的变量questions的类型没有定义好,于是找到上面提示的UploadAction查看,发现
private List questions;
这里忘记了些List的类型,应该改成这样:
private List
为了确保正确修改,重新部署项目,正常访问。
遇到这类问题只能根据详细的提示信息查找相关代码仔细的检查了,包括看看有没有拼写错误,路径有没有写错,方法名,或是重启服务器,重新部署。