Help with my java servlet homework
I am getting error saying:
root cause
java.lang.Error: Unresolved compilation problem:
Arrays cannot be resolved
Sorting.process(Sorting.java:38)
Sorting.doGet(Sorting.java:14)
javax.servlet.http.HttpServlet.service(HttpServlet .java:690)
javax.servlet.http.HttpServlet.service(HttpServlet .java:803)
My code:
This is my HTML script
Code:
<!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>
<p>Sorting arrays</p>
<form action="Sorting" method=get>
<p>1 <input type=text name=word></p>
<input type=submit name=sort value=Submit>
</form>
</body>
</html>
This is my servlet:
Code:
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class Sorting extends HttpServlet
{
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException
{
String word = request.getParameter("word");
word = process(word);
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<html>");
out.println("<head>");
out.println("<title>Sorting Servlet</title>");
out.println("</head>");
out.println("<body>");
out.println(word);
out.println("</body>");
out.println("</html>");
}
public void doPost(HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException
{
doGet(request, response);
}
public String process(String word) {
StringBuilder buf = new StringBuilder(512);
if(word != null && word.trim().length() != 0) {
String arr[] = word.replaceAll("\\s+", "").split(",");
Arrays.sort(arr);
for(String str : arr) {
buf.append(str).append("<br>");
}
}
else {
buf.append("<br>").append("No input supplied").append("<br>");
}
return(buf.toString());
}
}