まず、htmlからサーブレットにパラメータを送信したいと思います。 次に、パラメータから配列を作成し、その配列を別のサーブレットに送信したいとします。サーブレット2で印刷するだけです。 あるサーブレットから別のサーブレットに配列を送信して印刷しますか?
public void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
//System.out.println("XML servlet called!");
response.setContentType("text/html");
response.getWriter();
//read value from selection
String videoname = request.getParameter("video");
String videoformat = request.getParameter("format");
String videoquality = request.getParameter("quality");
//System.out.println("Name" + videoname);
//System.out.println("format" + videoformat);
//System.out.println("quality" + videoquality);
String [] chain1 = {"v1","f1","q1"};
String [] chain2 = {"v1","f1","q2"};
if (videoname.equals(chain1[0]) && (videoformat.equals(chain1[1])) && (videoquality.equals(chain1[2]))){
request.setAttribute("chain",chain1);
}
}else if (videoname.equals(chain2[0]) && (videoformat.equals(chain2[1])) && (videoquality.equals(chain2[2]))){
request.setAttribute("chain",chain2);}
RequestDispatcher dispatch = request.getRequestDispatcher("/Servlet2");
dispatch.forward(request, response);
と第二サーブレットで
、私のコードは次のとおりです:String value = (String)request.getAttribute("chain");
System.out.println("Chain is" + value);
私の問題は、これはdoesnの `tの仕事である は、ここに私のコードです。私には2つの問題があります。 1)attribiuteを送信する方法2)同じmashinでservlet2の結果を見ることは可能ですか?私は同じプロジェクトでServlet2という名前の別のクラスを作成し、web.xmlで名前とパスを定義するだけです。それは正しいのですか?