直接上代码:
head.jsp
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.0//EN"
"http://www.wapforum.org/DTD/xhtml-mobile10.dtd">
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String acceptHeader = request.getHeader("accept");
if (acceptHeader.indexOf("application/vnd.wap.xhtml+xml") != -1)
response.setContentType("application/vnd.wap.xhtml+xml");
else if (acceptHeader.indexOf("application/xhtml+xml") != -1)
response.setContentType("application/xhtml+xml");
else
response.setContentType("text/html");
%>
main.jsp
<%@ include file="header.jsp"%>
<%@ include file="checkSession.jsp"%>
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
………………
%>
<html xmlns="http://www.w3.org/1999/xhtml"
>
<head>
<title>……</title>
<link href="css/index.css" rel="stylesheet" type="text/css"/>
</head>
<body>
………………
</body>
</html>
注意事项 :1.head.jsp的前两行必须必须在每个文档的前两行。所以在main.jsp中include head.jsp。
2.所有的的标签必须闭包(input好像不用,但<br>必须闭包,即<br/>);
3.由于文件在传输中先转换成xml文件,所以需要转义的必须在界面上手工转义,如&->&,在传递多个参数时用的着。