-1

My JSP gives error 404 when I run Can anybody help me to find where is my mistake? I created jsp page that takes request parameter(background colors) and respond. I needed to call method from java class. I ALSO PLACED MY JSP PAGE IN WEB-INF Folder.Here is my code.

     <%@ 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>
user245548
  • 11
  • 7

1 Answers1

0

access this url localhost:9342/MyProject/MyJSP.jsp instead localhost:9342/MyProject/WEB-INF/MyJSP.jsp also read link

edited on Null pointer exception:

use if condition as I mentioned

<% 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
Community
  • 1
  • 1
Mohsin AR
  • 2,998
  • 2
  • 24
  • 36