jsp页面乱码问题
分两种:
Get方式传递数据解决办法:
<%
String username = request.getParameter("username");
byte[] bytes = username.getBytes("iso-8859-1");
String result = new String(bytes, "gb2312");
out.print(result);
%>
Post方式解决办法:request.setCharacterEncoding("gb2312");
相关文档:
最基本的乱码问题
这个乱码问题是最简单的乱码问题。一般新会出现。就是页面编码不一致导致的乱码。
Html代码:
<%@ page language="java" pageEncoding="UTF-8"%>
<%@ page contentType="text/html;charset=iso8859-1"%>
<html>
<head>
<title ......
1.request对象
该对象封装了用户提交的信息,通过调用该对象的响应的方法可以获取用户提交的信息。
当request对象获取用户提交的汉字字符时,会产生乱码,由下面的方法可以解决:
Sting s2 = new String(s1.getBytes("iso8859-1"),"GB2312")进行转换。
request常用的方法 ......
servlet中获得项目绝对路径
String filePath=this.getServletConfig().getServletContext().getRealPath("/");
根目录所对应的绝对路径:request.getServletPath();
文件的绝对路径 :request.getSession().getServletContext().getRealPath(request.getRequestURI())
当前web应用的绝对路径 :servletConfig.getServletCo ......
实现JSP自定义标签的一种方法:
1.写一个类继承TagSupport或其他Tag的实现类。
public class AllTag extends TagSupport {
@Override
public int doStartTag() throws JspException {
JspWriter out = pageContext.getOut();
try {
out.append("Hello World.");
} catch (IOException e) {
e.pri ......