1、使用form表单 action对象可以是jsp、servlet 点击 submit后 地址改变 页面跳转
<FORM name="LoginForm" action="tr" method="GET"> name: <input type="text" name="nu1" /> <br /><br /> password: <input type="password" name="nu2" /><br /><br /> <input type="submit" value="Submit" /> </FORM>
或者:
<FORM name="LoginForm" action="tr" method="GET"> name: <input type="text" name="nu1" /> <br /><br /> password: <input type="password" name="nu2" /><br /><br /> <input type="button" onclick="check()" value="submit" /> </FORM>
<script type="text/javascript"> function check(){ document.LoginForm.submit(); } </script>
相应的servlet:
<servlet> <servlet-name>tr</servlet-name> <servlet-class>tr</servlet-class> </servlet> <servlet-mapping> <servlet-name>tr</servlet-name> <url-pattern>/tr</url-pattern> </servlet-mapping>
源程序:
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html"); String uname = request.getParameter("nu1"); String upassword = request.getParameter("nu2"); PrintWriter ou = response.getWriter(); ou.println("userddd: "+uname+"<br>"); ou.println("passdddword: "+upassword+"<br>"); }