您好我是JSP的新手,我正在尝试将W3School的Ajax示例转换为jsp,但我无法这样做。任何人都可以帮忙。
这是PHP示例
http://www.w3schools.com/php/php_ajax_php.asp
这是ASP示例
http://www.w3schools.com/ajax/ajax_asp.asp
我已尝试使用java的substring函数但未能这样做。
提前致谢。
答案 0 :(得分:0)
我的理解是你想将PHP / ASP代码转换为jsp。这是jsp代码。请将此代码保存在gethint.jsp页面中,并在html页面中更改URL以定位jsp页面
<%@page import="java.util.Arrays"%>
<%
// Array with names
String hint = " ";
String[] a = {
"Anna","Brittany","Cinderella","Diana","Eva","Fiona","Gunda",
"Hege","Inga","Johanna","Kitty","Linda","Nina","Ophelia"
,"Petunia","Amanda","Raquel","Cindy","Doris","Eve","Evita","Sunniva"
,"Tove","Unni","Violet","Liza","Elizabeth","Ellen","Wenche","Vicky"
};
// get the q parameter from URL
String q = request.getParameter("q");
if (q != " ") {
for(String name : a )
{
if(name.toLowerCase().startsWith(q.toLowerCase()))
{
if(hint == " ")
{
hint = name;
}
else
{
hint = hint + ", " + name;
}
}
}
}
if(hint == " ")
{
out.println("No suggestion");
}
else{
out.println(hint);
}
%>