jsp scriptlet 内部 class 中的非法静态声明

Illegal static declaration in inner class in jsp scriplet

这个错误是什么意思??如何解决?我的错误在主语句中,请建议我解决方案或比这更好的方法来获取经纬度值并将地点作为输入....谢谢。

 <html>
    <%@page import="javaroots.latlong.*" %>
     <%@page import="javaroots.latlong.Location" %>
     <%@page import="javaroots.latlong.Geometry" %>
     <%@page import="javaroots.latlong.Result" %>
     <%@page import="javaroots.latlong.GoogleResponse" %>

     <%@page import="java.io.ByteArrayOutputStream" %>
     <%@page import="org.codehaus.jackson.annotate.JsonIgnore;" %>
     <%@page import=" java.io.IOException" %>
     <%@page import="java.io.InputStream" %>
     <%@page import="java.net.URL" %>
     <%@page import="java.net.URLConnection" %>
      <%@page import="java.net.URLEncoder" %>
     <%@page import="java.util.*" %>
    <%@page import="org.apache.commons.io.IOUtils" %>
  <%@page import="org.codehaus.jackson.map.ObjectMapper" %>




<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>JSP Page</title>
</head>
<body>
    <h1>Hello World!</h1>

    <%! 
        public static class AddressConverter  {
 private static final String URL = "http://maps.googleapis.com/maps/api/geocode/json";

 public GoogleResponse convertToLatLong(String fullAddress) throws IOException {

  URL url = new URL(URL + "?address="
+ URLEncoder.encode(fullAddress, "UTF-8") + "&sensor=false");
  // Open the Connection
  URLConnection conn = url.openConnection();

  InputStream in = conn.getInputStream() ;
  ObjectMapper mapper = new ObjectMapper();
  GoogleResponse response = (GoogleResponse)mapper.readValue(in,GoogleResponse.class);
  in.close();
  return response;


 }

 public GoogleResponse convertFromLatLong(String latlongString) throws IOException {

  URL url = new URL(URL + "?latlng="
+ URLEncoder.encode(latlongString, "UTF-8") + "&sensor=false");
  // Open the Connection
  URLConnection conn = url.openConnection();

  InputStream in = conn.getInputStream() ;
  ObjectMapper mapper = new ObjectMapper();
  GoogleResponse response = (GoogleResponse)mapper.readValue(in,GoogleResponse.class);
  in.close();
  return response;

 } 

 public class GoogleResponse {
    private Result[] results ;
 private String status ;

 public Result[] getResults() {
  return results;
 }
 public void setResults(Result[] results) {
  this.results = results;
 }
 public String getStatus() {
  return status;
 }
 public void setStatus(String status) {
  this.status = status;
 }


  public static void main(String[] args) throws IOException 

  {



  GoogleResponse res = new AddressConverter().convertToLatLong("uppal, India");
  if(res.getStatus().equals("OK"))
  {
   for(Result result : res.getResults())
   {
    System.out.println("Lattitude of address is :"  +result.getGeometry().getLocation().getLat());
    System.out.println("Longitude of address is :" + result.getGeometry().getLocation().getLng());
    System.out.println("Location is " + result.getFormatted_address());
   }
  }
  else
   {
   System.out.println(res.getStatus());
  }

  System.out.println("\n");







}
  }    



    public class Geometry {

 private Location location ;

 private String location_type;

 @JsonIgnore
 private Object bounds;

 @JsonIgnore

 private Object viewport;

 public Location getLocation() {
  return location;
 }

 public void setLocation(Location location) {
  this.location = location;
 }

 public String getLocation_type() {
  return location_type;
 }

 public void setLocation_type(String location_type) {
  this.location_type = location_type;
 }

 public Object getBounds() {
  return bounds;
 }

 public void setBounds(Object bounds) {
  this.bounds = bounds;
 }

 public Object getViewport() {
  return viewport;
 }

 public void setViewport(Object viewport) {
  this.viewport = viewport;
 }




}
public class Location {

 private String lat;

 private String lng;

 public String getLat() {
  return lat;
 }

 public void setLat(String lat) {
  this.lat = lat;
 }

 public String getLng() {
  return lng;
 }

 public void setLng(String lng) {
  this.lng = lng;
}
}
public class Result {

 private String formatted_address;

 private boolean partial_match;

 private Geometry geometry;



@JsonIgnore
private String place_id;
 @JsonIgnore
 private Object address_components;

 @JsonIgnore
 private Object types;

 public String getFormatted_address() {
  return formatted_address;
 }

 public void setFormatted_address(String formatted_address) {
  this.formatted_address = formatted_address;
 }

 public boolean isPartial_match() {
  return partial_match;
 }

 public void setPartial_match(boolean partial_match) {
  this.partial_match = partial_match;
 }

 public Geometry getGeometry() {
  return geometry;
 }

 public void setGeometry(Geometry geometry) {
  this.geometry = geometry;
 }

 public Object getAddress_components() {
  return address_components;
 }

 public void setAddress_components(Object address_components) {
  this.address_components = address_components;
 }

 public Object getTypes() {
  return types;
 }

 public void setTypes(Object types) {
  this.types = types;
 }



}


        %>
    </body>
</html>

修饰符 static 只允许在常量变量声明中使用。您不能在内部 class 中定义静态方法。你不能使用 :

 public static void main(String[] args) throws IOException 

在你的内心class。

详情请见: Modifier static is only allowed in constant variable declarations.