用session获取登陆页面消息代码

html页面代码:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>MyHtml.html</title>

    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="this is my page">
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
    <meta http-equiv="Expires" content=" 0"/>
<meta http-equiv="Cache-Control"content="no-Cache"/>
<meta http-equiv="Pragma"content= "no-Cache"/>
    <meta http-equiv="Refresh" content="3;url=http://www.baidu.com"/>
    <!--<link rel="stylesheet" type="text/css" href="./styles.css">-->


  </head>
  
  <body>
  <form id="form1" name="form1" method="post" action="servlet/SubmitServlet">
  <p>用户名:
    <label for="username"></label>
    <input type="text" name="username" id="username" />
  </p>
  <p>密码:
    <label for="password"></label>
    <input type="password" name="password" id="password" />
  </p>
  <p>性别:
    <input type="radio" name="sex" id="radio" value="男" />
    男
    <label for="sex"></label>
    <input type="radio" name="sex" id="radio2" value="女" />
    女
    <label for="sex"></label>
  </p>
  <p>爱好:
    <input name="lover" type="checkbox" id="lover" value="listen" />
    <label for="lover"></label>
  听歌
  <input name="lover" type="checkbox" id="lover" value="eat" />
  <label for="lover"></label>
  吃好吃的
  <input name="lover" type="checkbox" id="lover" value="look" />
  <label for="lover"></label>
  看书</p>
  <p>出生日期:
    <label for="year"></label>
    <select name="year" id="year">
      <option value="1990">1990年</option>
      <option value="1991">1991年</option>
      <option value="1992">1992年</option>
    </select>
  年
  <label for="month"></label>
  <select name="month" size="5" id="month">
    <option value="1">1月</option>
    <option value="2">2月</option>
    <option value="3">3月</option>
  </select>
  月</p>
  <p>
    <input type="submit" name="button" id="button" value="提交" />
    <input type="reset" name="button2" id="button2" value="重置" />
  </p>
</form>


  </body>
</html>


session页面代码:

package com.hbsi.csdn.RequestTest;


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;


import sun.net.www.content.image.png;


public class SubmitServlet extends HttpServlet {


/**
* Constructor of the object.
*/
public SubmitServlet() {
super();
}


/**
* Destruction of the servlet. <br>
*/
public void destroy() {
super.destroy(); // Just puts "destroy" string in log
// Put your code here
}


/**
* The doGet method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to get.

* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {


this.doPost(request, response);
}


/**
* The doPost method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to post.

* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {


response.setDateHeader("Expires", 0);
response.setHeader("Cache-Control", "no-Cache");
response.setHeader("Pragma", "no-Cache");


response.setContentType("text/html;charset=utf-8");
PrintWriter out=response.getWriter();

String username=request.getParameter("username");
String password=request.getParameter("password");
String sex=request.getParameter("sex");

String lover[]=request.getParameterValues("lover");
String temp="";
for(int i=0;i<lover.length;i++){
temp=temp+lover[i];
}

String year=request.getParameter("year");
String month=request.getParameter("month");


out.println("用户名:"+new String(username.getBytes("ISO8859-1"),"utf-8")+"<br/>");
out.println("密码:"+new String(password.getBytes("ISO8859-1"),"utf-8")+"<br/>");
out.println("性别:"+new String(sex.getBytes("ISO8859-1"),"utf-8")+"<br/>");
out.println("爱好:"+temp+"<br/>");
out.println("出生日期:"+year+"年");
out.println(month+"月"+"<br/>");

}


/**
* Initialization of the servlet. <br>
*
* @throws ServletException if an error occurs
*/
public void init() throws ServletException {
// Put your code here
}


}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值