JSP中的细节

1.注释

  <!---->与<%---->的区别

2.ContentType与pageEncoding中的charset的区别

  pageEncoding指的是服务器加载jsp时编码,文件编码与其不一致,JSP翻译成的Servlet中会有中文乱码。

  ContentType是指定服务器和浏览器用什么显示的编码,如果JSP翻译成的Servlet中有中文乱码,无论ContentType的charset设置成什么永远是乱码,因为浏览器

输出的JSP翻译过后的字符,这个字符本身就是乱码的;同理,如果JSP翻译成的Servlet中没有中文乱码,无论ContentType的charset设置成什么永远都不会乱码。

   即ContentType与pageEncoding中的chartset是没有关联的。

   

  另外,关于乱码。要注意字符原本就是乱码字符的情况。

 

3.jsp中的include指令

  问题1:一个jsp中嵌入另外一个jsp页面

      

An error occurred at line: 3 in the jsp file: /include/2.jsp
Duplicate local variable path
1: <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
2: <%
3: String path = request.getContextPath();
4: String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
5: %>

  这得从JSP的翻译说起,jsp2中也有一个<% path = ... basePath = ...%>,翻译就是重复定义了变量,自然而然就会出错了。把jsp2的这段代码删除掉就没有问题了。

 

 

 

 

    

posted @ 2016-03-04 17:26  行意天下  阅读(179)  评论(0编辑  收藏  举报