2017-04-22 89 views
-1

我的JSP在運行時給出錯誤404有人能幫我找到我的錯誤在哪裏嗎?我創建了帶請求參數(背景顏色)並響應的jsp頁面。我需要從java類調用方法。我還將我的JSP頁面放在WEB-INF文件夾中。這裏是我的代碼。JSP錯誤404我的錯誤在哪裏

 <%@ page language="java" contentType="text/html; charset=ISO-8859-1" 
pageEncoding="ISO-8859-1"%> 
<%@ page import="com.java.MyJsp"%> 
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
    "http://www.w3.org/TR/html4/loose.dtd"> 
    <html> 
    <head> 
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> 
<title>Insert title here</title> 
</head> 
<body> 
<form action="./myjsp.jsp"> 
<input type="radio" name="color" value="color1" > Yellow<br> 
<input type="radio" name="color" value="color2"> White<br> 
<input type="radio" name="color" value="color3"> Gray<br> 

<input type="submit" value="go"> 
</form> 

     <% String colors[]=request.getParameterValues("color"); 
     for(int i=0;i<colors.length;i++){ 
     if(colors[i].equals("")||colors[i]==null){ %> 
     <body style="background-color:<%=com.java.Myjsp.myColor() 
     %>;"> 
     <% } 


     if(colors[i].equals("yellow")){ 

    out.println("<html> <style> body{background-color:yellow;} </style> 
    </html>"); 
    } 
    if(colors[i].equals("white")){ 

     out.println("<html> <style> body{background-color:white;} </style> 
    </html>"); 
    } 
    if(colors[i].equals("gray")){ 

     out.println("<html> <style> body{background-color:gray;} </style> 
     </html>"); 
     } 
     } 
     %> 

    </body> 
    </html> 
+0

你怎麼訪問你的JSP頁面條件在瀏覽器中? –

+0

我剛剛在eclipse上運行服務器ee – user245548

+0

發佈你的服務器代碼和'url'你正在訪問 –

回答

0

訪問此網址localhost:9342/MyProject/MyJSP.jsp代替 localhost:9342/MyProject/WEB-INF/MyJSP.jspread link

對空指針異常編輯:

的使用,如果正如我所提到

<% String colors[]=request.getParameterValues("color"); 
    if(colors !=null) { 
     for(int i=0;i<colors.length;i++){ 
     if(colors[i].equals("")||colors[i]==null){ %> 
     <body style="background-color:<%=com.java.Myjsp.myColor() 
     %>;"> 
     <% } 
    } // end of if statement this should be placed after loop block 
+0

它給出空指針異常 – user245548

+0

'顏色[]'可能爲空檢查您的自我或調試它 –

+0

它不起作用。 – user245548