【问题标题】:JSP error 404 where is my mistakeJSP错误404我的错误在哪里
【发布时间】:2017-04-22 10:41:21
【问题描述】:

我的 JSP 在我运行时出现错误 404 谁能帮我找出我的错误在哪里?我创建了带有请求参数(背景颜色)并响应的 jsp 页面。我需要从 java 类中调用方法。我还将我的 JSP 页面放在 WEB-INF 文件夹中。这是我的代码。

     <%@ 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>

【问题讨论】:

  • 你如何在浏览器中访问你的jsp页面?
  • 我只是在 eclipse ee 上的服务器上运行
  • 发布你的服务器代码和url你正在访问
  • 我将我的 JSP 页面放在了 web INF 中,这是一个原因吗?

标签: java eclipse jsp


【解决方案1】:

改为访问此网址localhost:9342/MyProject/MyJSP.jsp localhost:9342/MyProject/WEB-INF/MyJSP.jsp 还有read link

已编辑空指针异常

使用我提到的 if 条件

<% 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

【讨论】:

  • colors[] 可能是你自己的空检查或调试它
  • 你应该发布你的服务器日志,这会很有帮助
  • 在 for 循环中显示 Java.lang 空指针异常
  • 读取空指针异常处理链接stackoverflow.com/questions/218384/…
猜你喜欢
  • 1970-01-01
  • 2017-10-17
  • 1970-01-01
  • 2018-09-02
  • 2014-04-19
  • 1970-01-01
  • 1970-01-01
  • 2016-05-22
  • 2015-04-11
相关资源
最近更新 更多