------------------SubmitMessage.jsp-------------------------<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<center>
<form action="SubmitPage.jsp" method="post">
用户名:<input type="text" name="name" size="20"><br>
留 言:<input type="textarea" name="message" size="300"><br>
<input type="submit" value="提交"><input type="Reset" value="重添">
</form></center></body>
</html>
------------------------SubmitPage.jsp---------------------<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<jsp:useBean id = "sub" scope="page" class="com.beans.GuestBookBean"/>
<jsp:setProperty name="sub" property="*"/>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>SumbitPage</title>
</head>
<body>
用户是:<%=sub.getName()%><br>
留 言:<%=sub.getMessage() %><br></body>
</html>-----------GuestBookBean.java--------------package com.beans;public class GuestBookBean {
private int id;
private String name;
private String message;
private String savetime;
/**
* @return Returns the id.
*/
public int getId() {
return id;
}
/**
* @param id The id to set.
*/
public void setId(int id) {
this.id = id;
}
/**
* @return Returns the message.
*/
public String getMessage() {
return message;
}
/**
* @param message The message to set.
*/
public void setMessage(String message) {
this.message = message;
}
/**
* @return Returns the name.
*/
public String getName() {
return name;
}
/**
* @param name The name to set.
*/
public void setName(String name) {
this.name = name;
}
/**
* @return Returns the savetime.
*/
public String getSavetime() {
return savetime;
}
/**
* @param savetime The savetime to set.
*/
public void setSavetime(String savetime) {
this.savetime = savetime;
}
}
pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<center>
<form action="SubmitPage.jsp" method="post">
用户名:<input type="text" name="name" size="20"><br>
留 言:<input type="textarea" name="message" size="300"><br>
<input type="submit" value="提交"><input type="Reset" value="重添">
</form></center></body>
</html>
------------------------SubmitPage.jsp---------------------<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<jsp:useBean id = "sub" scope="page" class="com.beans.GuestBookBean"/>
<jsp:setProperty name="sub" property="*"/>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>SumbitPage</title>
</head>
<body>
用户是:<%=sub.getName()%><br>
留 言:<%=sub.getMessage() %><br></body>
</html>-----------GuestBookBean.java--------------package com.beans;public class GuestBookBean {
private int id;
private String name;
private String message;
private String savetime;
/**
* @return Returns the id.
*/
public int getId() {
return id;
}
/**
* @param id The id to set.
*/
public void setId(int id) {
this.id = id;
}
/**
* @return Returns the message.
*/
public String getMessage() {
return message;
}
/**
* @param message The message to set.
*/
public void setMessage(String message) {
this.message = message;
}
/**
* @return Returns the name.
*/
public String getName() {
return name;
}
/**
* @param name The name to set.
*/
public void setName(String name) {
this.name = name;
}
/**
* @return Returns the savetime.
*/
public String getSavetime() {
return savetime;
}
/**
* @param savetime The savetime to set.
*/
public void setSavetime(String savetime) {
this.savetime = savetime;
}
}
解决方案 »
- Mysql怎么设置记录的ID编号,使每次取出的记录都是当前最新更新的前几条记录?
- 请教高手Hibernate错误问题
- 实现Web上行式输入打勾多选和批量删除
- 有jsp基础,想用CMS做网站。网上有好多PHP的CMS。我有必要学习PHP吗?
- 关于dwr 未定义问题,在本地开发环境,测试环境通过,但发布到服务器,用户方就js 错误 dwr 未定义
- 菜鸟求教 result问题
- 新手求教!服务器转发的问题!唉,愁死人啊
- webwork 的 checkbox 如何在页面提交之后还保存状态啊
- response.redirect问题
- Struts2 get请求,Url上带参数,action会执行两次,求探讨,求为什么?
- <textarea>这个标签怎么设置一下可以自动换行?
- jsp连接SQL SERVER200出现异常SQLServer 2000 Driver for JDBC][SQLServer]对象名 'board' 无效。
/*
* ====================================================================
*
* JavaWebStudio 开源项目
*
* Struts_db v0 dot 1
*
* ====================================================================
*/import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
/**
* 中文过滤器
*/
public class SetCharacterEncodingFilter implements Filter {
// ----------------------------------------------------- Instance Variables
/**
* The default character encoding to set for requests that pass through
* this filter.
*/
protected String encoding = null;
/**
* The filter configuration object we are associated with. If this value
* is null, this filter instance is not currently configured.
*/
protected FilterConfig filterConfig = null;
/**
* Should a character encoding specified by the client be ignored?
*/
protected boolean ignore = true;
// --------------------------------------------------------- Public Methods
/**
* Take this filter out of service.
*/
public void destroy() {
this.encoding = null;
this.filterConfig = null;
}
/**
* Select and set (if specified) the character encoding to be used to
* interpret request parameters for this request.
*
* at param request The servlet request we are processing
* @param result The servlet response we are creating
* @param chain The filter chain we are processing
*
* @exception IOException if an input/output error occurs
* @exception ServletException if a servlet error occurs
*/
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain)
throws IOException, ServletException {
// Conditionally select and set the character encoding to be used
if (ignore||(request.getCharacterEncoding() == null)) {
String encoding = selectEncoding(request);
if (encoding != null)
request.setCharacterEncoding(encoding);
}
// Pass control on to the next filter
chain.doFilter(request, response);
}
/**
* Place this filter into service.
*
* at param filterConfig The filter configuration object
*/
public void init(FilterConfig filterConfig) throws ServletException {
this.filterConfig = filterConfig;
this.encoding = filterConfig.getInitParameter("encoding");
String value = filterConfig.getInitParameter("ignore");
if (value == null)
this.ignore = true;
else if (value.equalsIgnoreCase("true"))
this.ignore = true;
else if (value.equalsIgnoreCase("yes"))
this.ignore = true;
else
this.ignore = false;
}
// ------------------------------------------------------ Protected Methods
/**
* Select an appropriate character encoding to be used, based on the
* characteristics of the current request and/or filter initialization
* parameters. If no character encoding should be set, return
* null.
* * The default implementation unconditionally returns the value configured
* by the encoding initialization parameter for this
* filter.
*
* at param request The servlet request we are processing
*/
protected String selectEncoding(ServletRequest request) {
return (this.encoding);
}
}//EOC
=============web.xml=============配制<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>GuestBook</display-name> <welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list> <filter>
<filter-name>SetCharacterEncodingFilter</filter-name>
<filter-class>SetCharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>GB2312</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>SetCharacterEncodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping></web-app>哪位大哥能帮忙啊!谢谢啦!
用户是:<%=sub.getName()%><br>
留 言:<%=sub.getMessage() %><br>
这里都是乱码 过滤器也改成UTF-8试验过。不行!要疯啦~~~~~~~~~~~~~~~~~~
应该写到哪里啊?是bean中吗?
不是很明白啊~~~
过滤器的作用就是转换字符编码。