2017-02-14 47 views
0
<%@ page import="java.util.*" %> 
<html> 
<head><title>Echo JSP</title></head> 
<body> 
<h1>Incoming HTTP Request</h1> 

<table border="0" cellpadding="3" cellspacing="0" width="100%"> 

<% 
Enumeration eNames = request.getHeaderNames(); 

while (eNames.hasMoreElements()) { 

    String name = (String) eNames.nextElement(); 

    String value = normalize(request.getHeader(name)); 

    %> 

    <tr><td><%= name %></td><td><%= value %></td></tr> 

    <% 
} 

%> 
</table> 

</body> 

</html> 



<% 
private String normalize (String value) { 
StringBuffer line = new StringBuffer(); 

for (int i = 0; i < value.length(); i++) { 
    char c = value.charAt(i); 

    line.append(c); 

    if (c == ';') { 
     line.append("<br>"); 

    } 

} 

return line.toString(); 
} 
%> 

我得到一個編譯錯誤The method normalize(String) is undefined for the type index_jsp在這條線的類型:方法正規化(字符串)是未定義index_jsp

字符串值=歸一化(request.getHeader(名));

我不知道java,這只是我需要運行的測試頁面。誰能幫忙?

回答

0

<%! %> tags中附上'normalize'方法。您將它包含在<% %>之內,而不是用於方法調用。

相關問題