注册
 找回密码
 注册
江西广告网
查看: 826|回复: 0
打印 上一主题 下一主题

可返回站点的根路径request.getContextPath()

[复制链接]

该用户从未签到

1
跳转到指定楼层
发表于 2009-2-24 10:37:31 | 只看该作者 回帖奖励 |正序浏览 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有帐号?注册

x
package com.v512.webproject2; import java.io.IOException; import java.io.PrintWriter; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; public class LoginFormServlet extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=utf-8"); PrintWriter out = response.getWriter(); out.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">"); out.println("<HTML>"); out.println(" <HEAD><TITLE>A Servlet</TITLE></HEAD>"); out.println(" <BODY>"); out.print("<form method=\"post\" action=\" " request.getContextPath() "/servlet/loginForm\" >"); out.println("用户名:<input type='text' name='username' size='18'>" "<br>"); out.println("密 码:<input type='password' name='password' size='20'>" "<br>"); out.println("<input type='submit' name='submit' value='提交'>"); out.print("<input type='reset' name='reset' value='重置'>"); out.print("</form>"); out.println("request.getContextPath" "用来活动web应用的名字webprject2" "<br>"); out.println("用post的提交方式提交到自己的post" "<br>"); out.println("解决乱码request.setCharacterEncoding(\"utf-8\")" "<br>"); out.println(" </BODY>"); out.println("</HTML>"); out.flush(); out.close(); } public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=utf-8"); PrintWriter out = response.getWriter(); out.println("<HTML>"); out.println(" <HEAD><TITLE>A Servlet</TITLE></HEAD>"); out.println(" <BODY>"); request.setCharacterEncoding("utf-8"); out.print("用户名:" request.getParameter("username") "<br>"); out.print("密 码:" request.getParameter("password") "<br>"); out.println(" </BODY>"); out.println("</HTML>"); out.flush(); out.close(); } }
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表