서블릿이 있습니다. 그 안에 나는 선을 형성하고 브라우저 링크를 입력하면 그는 선을 회전 시킨다고 말했습니다. 모든 것이 좋습니다. 이제 문자열 배열을 만들고 링크의 매개 변수에 따라 특정 행을 회전합니다. 어떻게하나요?
@WebServlet("/goods")
public class GoodsServlet extends HttpServlet {
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.print("{\"name\":\"Pavel\",\"sname\":\"Petrashov\",\"age\":24,\"params\":{\"heigth\":188, \"weight\":72, \"strong\":100}}");
}
}
그리고 나는 갖고 싶다
List<String> list = new ArrayList<String>();
list.add("{\"name\":\"Pavel\",\"sname\":\"Petrashov\",\"age\":24,\"params\":{\"heigth\":188, \"weight\":72, \"strong\":100}}");
list.add("{\"name\":\"Bill\",\"sname\":\"Gey\",\"age\":99,\"params\":{\"heigth\":188, \"weight\":70, \"strong\":100}}");
list.add("{\"name\":\"Uill\",\"sname\":\"Smitt\",\"age\":12,\"params\":{\"heigth\":188, \"weight\":99, \"strong\":100}}");
내 참조 http://localhost:666/sg/goods
가 배열 요소를 반환하는 매개 변수 를 사용했는지 확인하기 위해
GET 매개 변수에 따라 목록의 문자열 중 하나를 인쇄하려는 의미입니까? 그것이 당신이 원하는 것이라면 String myParameter = request.getParameter("param");
get 매개 변수를 제공합니다. 매개 변수를 URL과 같은 쿼리 문자열로 전달합니다 http://localhost:666/sg/goods?param=2
.
이제 매개 변수를 사용하여 목록에서 문자열을 가져옵니다.
try{ int index = Integer.parseInt(myParameter); out.println(list.get(index)); } catch(IndexOutOfBoundsException|NumberFormatException ex){ System.err.println("Invalid get parameter"); }
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다