jsp问题字符乱码问题,求快速解决

zs312979674 2011-05-10 08:17:04
下面是JSP页面

<%@ page language="java" import="java.util.*" pageEncoding="GBK"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">

<title>edit pet page</title>

<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->

</head>

<body>
<form name="pet" action="DoEditPet" >

pet_name:<input name="name"type="text" value="${sessionScope.petinfo.pet_name}"/><br/>
pet_owner_email:<input name="email" type="text" value="${sessionScope.petinfo.pet_owner_email}"/><br/>
<input type="reset" value="重置"/> <input type="submit" value="提交"/>

</form>
</body>
</html>



以下是 servlet java 代码

package Contrallor;

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 javax.servlet.http.HttpSession;

import dao.impl.PetinfoEditBizJdbcImpl;

import entity.Petinfo;

public class DoEditPet extends HttpServlet {

/**
* 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 {

HttpSession session = request.getSession();
Petinfo petinfo = (Petinfo)session.getAttribute("petinfo");

petinfo.setPet_name(request.getParameter("name"));
petinfo.setPet_owner_email(request.getParameter("email"));
System.out.println(petinfo.getPet_name());
String result = new PetinfoEditBizJdbcImpl().edit(petinfo);

if(result.equals("success"))
response.sendRedirect("/pet/showpet.jsp?id="+petinfo.getPet_id());
else
{
request.setAttribute("errormessage", "编辑错误");
request.getRequestDispatcher("/error.jsp").forward(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 {

doGet(request,response);
}

}



在更新成功后跳转到另外一个显示页面

<%@ page language="java" import="java.util.*" pageEncoding="GBK"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">

<title>show pet page</title>

<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
<jsp:useBean id="petinfo" class="entity.Petinfo" scope="session"></jsp:useBean>
</head>

<body>
<div align="center">
${petinfo.pet_id }<br />
${petinfo.pet_name }<br />

<img alt="${petinfo.pet_name} " src="${petinfo.pet_pic}">
</div>
</body>
</html>

...全文
37 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
zs312979674 2011-05-10
  • 打赏
  • 举报
回复
在最下面那个页面总是有字符乱码 ? 坐等 解决、、

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧