<%@ page language="java" contentType="text/html" pageEncoding="GBK"%>
<%@ page import="javax.servlet.http.*" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>'index.jsp'</title>
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body>
<%
String welcome = "第一次访问";
String[] info = new String[]{"","",""};
Cookie[] cook = request.getCookies();
if(cook!=null){
for(int i=0;i<cook.length;i++){
if(cook[i].getName().equals("mrCookInfo")){
info = cook[i].getValue().split("#");
welcome = ",欢迎回来!";
}
}
}
%>
<%=info[0]+welcome %>
<form action="show.jsp" method="post">
<ul style="line-height: 23">
<li>姓 名:<input name="name" type="text" value="<%=info[0] %>">
<li>出生日期:<input name="birthday" type="text" value="<%=info[1] %>">
<li>邮箱地址:<input name="mail" type="text" value="<%=info[2] %>">
<li><input type="submit" value="提交">
</ul>
</form>
</body>
</html>
//上面这个是index的,下面这个是show的,华丽的分割浮-------------------------------------
<%@ page language="java" contentType="text/html" pageEncoding="GBK"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>'show.jsp'</title>
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body>
<%
String name = request.getParameter("name");
String birthday = request.getParameter("birthday");
String mail = request.getParameter("mail");
Cookie myCook = new Cookie("myCookInfo",name+"#"+birthday+"#"+mail);
myCook.setMaxAge(60*60*24*365);
response.addCookie(myCook);
%>
表单提交成功
<ul style="line-height: 24px">
<li>姓名:<%= new String(name.getBytes("iso-8859-1"),"gbk")%>
<li>出生日期:<%= birthday %>
<li>电子邮箱:<%= mail %>
<li><a href="index.jsp">返回</a>
</ul>
</body>
</html>
//提问,为什么是失败了,到底哪里出问题了,eclipse也是用的gbk啊
|
|