此代码在编译时不包含错误,但在运行时会出错。

时间:2013-04-22 18:26:31

标签: web-services jsp

此代码在编译时不包含任何错误,但在运行时会出错。 我无法在 tomcat 7.0 上运行此代码。我开始多次重启它。您能否建议我如何改变代码以使其有效?

<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1" %>
<!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>
  <%@ page import="java.util.*" %>
    <body>
      <form action="MyWSserve" method="get">Enter Zip Code
        <br>
        <input type="text" name="zipcode"></input>
        <input type="submit" name="GO" value="GO"></input>
      </form>
      <% //Object obj=request.getAttribute("values"); 
      //if(obj instanceof ArrayList){ 
        //ArrayList<String>mylist = (ArrayList<String>)obj; }%>
      <% //Iterator<String>itr = mylist.iterator(); %>
      <% String[] strcode=(String[])request.getAttribute( "values"); %>
      <p>The Temperature in Centigrade <%=strcode[0] %><br></p>
      <p>The Temperature in Farenheit <%=s trcode[1] %><br></p>
      <p>The Pressure is <%=s trcode[2] %><br></p>
      <p>The weather Condition is <%=s trcode[3] %><br></p>
    </body>
</html>

1 个答案:

答案 0 :(得分:0)

试试这个:

<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1" %>
<!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>
  <%@ page import="java.util.*" %>
    <body>
      <form action="MyWSserve" method="get">Enter Zip Code
        <br>
        <input type="text" name="zipcode"></input>
        <input type="submit" name="GO" value="GO"></input>
      </form>
      <% //Object obj=request.getAttribute("values"); 
      //if(obj instanceof ArrayList){ 
        //ArrayList<String>mylist = (ArrayList<String>)obj; }%>
      <% //Iterator<String>itr = mylist.iterator(); %>
      <% String[] strcode = request.getParameterValues("values"); %>
      <% if (strcode != null && strcode.length >= 4) { %>
      <p>The Temperature in Centigrade <%=strcode[0] %><br></p>
      <p>The Temperature in Farenheit <%= strcode[1] %><br></p>
      <p>The Pressure is <%= strcode[2] %><br></p>
      <p>The weather Condition is <%= strcode[3] %><br></p>
      <% } else { %>
      <p>Call this page using 4 parameters called "values":
      <a href="?values=1st&values=2nd&values=3rd&values=4th">?values=1st&values=2nd&values=3rd&values=4th</a>
      <% } %>
    </body>
</html>