当前位置: 代码迷 >> Java Web开发 >> <jsp:include page = "<%=fileName>">该怎么解决
  详细解决方案

<jsp:include page = "<%=fileName>">该怎么解决

热度:2098   发布时间:2013-02-25 21:13:02.0
<jsp:include page = "<%=fileName>">
<%@ page contentType ="text/html;charset=GB2312" pageEncoding = "gb2312"%>
<%@page import = "java.io.*" %>
<html>
<body>
<%!
class FileJSP implements FilenameFilter{
String str = null;
FileJSP(String s){
str = "."+s;
}
public boolean accept(File dir,String name){
return name.endsWith(str);
}
}
String fileName;
%>
<p>下面列出了一些服务器上的JSP文件
<%
File dir = new File("E:\\apache-tomcat-7.0.23\\webapps\\demo");
FileJSP file_jsp = new FileJSP("jsp");
String file_name[] = dir.list(file_jsp);
for(int i = 0 ; i < file_name.length; i++){
out.print("<br>"+file_name[i]);
}
%>
<p>请输入一个JSP文件的名字,加载这个JSP文件:
<form action = "demo17.jsp" method = post name =form >
<input type = "text" name ="ok" >
<br>
<input type = "submit" value = "送出" name = submit>
</form>
<%
fileName =request.getParameter("ok");
 %>
 <jsp:include page = "<%=fileName %>"></jsp:include>

</body>
</html>



错误信息:

HTTP Status 500 - 

--------------------------------------------------------------------------------

type Exception report

message 

description The server encountered an internal error () that prevented it from fulfilling this request.

exception 

org.apache.jasper.JasperException: An exception occurred processing JSP page /demo17.jsp at line 35

32: <%
33: fileName =""+request.getParameter("ok");
34: %>
35: <jsp:include page = "<%=fileName %>"></jsp:include>
36: 
37: </body>
38: </html>


Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:568)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:460)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)


root cause 

java.io.FileNotFoundException: The requested resource (/demo/null) is not available
org.apache.catalina.servlets.DefaultServlet.serveResource(DefaultServlet.java:773)
org.apache.catalina.servlets.DefaultServlet.doGet(DefaultServlet.java:411)
javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
org.apache.jasper.runtime.JspRuntimeLibrary.include(JspRuntimeLibrary.java:954)
org.apache.jsp.demo17_jsp._jspService(demo17_jsp.java:102)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)



------解决方案--------------------------------------------------------
因为一开始进去的时候,你还没在你的id=“ok”的输入框中输入东西,所以取不到值。然后报错了,你加个if判断下应该就可以了~你可以尝试下吧
  相关解决方案