Java Servlets
<body> <form method="get" action="/servlet/hello"> If you don't mind me asking, what is your name? <input type="text" name="name"/> <input type="hidden" name="id" value="1234"/> <input type="hidden" name="degree" value="bs"/> <input type="submit"> <p/> </form> </body>
import java.io.*; import javax.servlet.*; import javax.servlet.http.*; public class ShoppingCartViewerHidden extends HttpServlet { public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { res.setContentType("text/html"); PrintWriter out = res.getWriter(); out.println("..."); // Cart items are passed in as the item parameter. String[] items = req.getParameterValues("item"); // Ask if the user wants to add more items or check out. // Include the current items as hidden fields so they'll be passed on. out.println("<form action=\"/servlet/ShoppingCart\" method=\"POST\">"); if (items != null) { for (int i = 0; i < items.length; i++) { out.println("<input type=\"HIDDEN\" name=\"item\" value=\"" + items[i] + "\">"); } } out.println("..."); } }
48 of 89