我是
靠谱客的博主
勤劳口红,这篇文章主要介绍
利用servlet输出CSS,现在分享给大家,希望可以做个参考。
一、Servlet类
import
java.io.IOException;
import
java.sql.Connection;
import
java.sql.SQLException;

import
javax.servlet.ServletException;
import
javax.servlet.ServletOutputStream;
import
javax.servlet.http.HttpServlet;
import
javax.servlet.http.HttpServletRequest;
import
javax.servlet.http.HttpServletResponse;

import
util.HtmlPage;
import
util.Mail;
import
util.PubFun;


public
class
CssCtrl
extends
HttpServlet
...
{

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)

throws ServletException, IOException ...{
String jspStr = "Page参数不能为空";
Connection conn = null;
resp.setContentType("text; charset=UTF-8");
HtmlPage page = new page.newadmin.LoadTemplatePage();//initHtmlPage(req.getParameter("cssid"));
ServletOutputStream out = resp.getOutputStream();

if (page == null) ...{
resp.sendRedirect("http://www.61live.com/index.html");
out.close();
return;
}

try ...{
conn = PubFun.getConn(true);
page.prepare(conn, req, resp);
jspStr = page.print();

} catch (Exception e) ...{
System.out.println(e.toString());
jspStr = e.toString();
Mail.send("xukai@61live.com", "xukai@61live.com",req.getRequestURI()+"?"+ req
.getQueryString(), e.getMessage(), null, "xukai@61live.com",
"xukai");
Mail.send("litao@61live.com", "xukai@61live.com",req.getRequestURI()+"?"+ req
.getQueryString(), e.getMessage(), null, "xukai@61live.com",
"xukai");

} finally ...{

if (conn != null) ...{

try ...{
conn.close();

} catch (SQLException e2) ...{
System.out.println(page.getClass().getName() + "conn.close() falied");
}
}
}

if(jspStr!=null)...{
out.print(jspStr);
}
out.close();
}

@Override
protected void doPost(HttpServletRequest arg0, HttpServletResponse arg1)

throws ServletException, IOException ...{
// TODO Auto-generated method stub
super.doPost(arg0, arg1);
}


private static HtmlPage initHtmlPage(String page) ...{
if (page.equals("LoadTemplatePage")) // 选择已有的图片标签


return new page.newadmin.LoadTemplatePage();
return null;
}
}
二、读取模板信息
package
page.newadmin;
import
util.HtmlPage;
import
javabean.Template;


public
class
LoadTemplatePage
extends
HtmlPage
...
{


public String print() throws Exception ...{
long cssid = this.getLongParameter("cssid", -1);
// 此文章的模板信息
Template temp = table.TemplateTable.selctTemplate(conn_, cssid);
StringBuffer strVal = new StringBuffer(temp.getCssCont());
return strVal.toString();
}
}
三、JSP页面 读取CSS
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@page import="javabean.Template" import="javabean.TopicTag"
%>
<%
Template template = (Template)request.getAttribute("template");
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title><%=art.getTitle()+"-成长网" %></title>
<meta name="description" content="<%=art.getPicDesc() %>" />
<meta name="keywords" content=" <%=art.getKeyword() %>" />
<%if(template==null){ %>
<link href="<%=request.getContextPath() _fcksavedurl=""<%=request.getContextPath()" %>/webapp/css/deafchild/style.css" rel="stylesheet" type="text/css" />
<%}else{ %>
<link href="<%=request.getContextPath()%>/webapp/css/deafchild/CssCtrl?cssid=<%=template.getCssId() %>" rel="stylesheet" type="text/css" />
<%} %>
四、数据库结构
8.
模板表:
tab_tempalte
字段说明
|
字段名
|
是否主键
|
数据类型
|
备注
|
模板ID
|
Css_id
|
T
|
number
|
|
模板名称
|
Css_name
|
F
|
Nvarchar2(100)
|
|
模板内容
|
Css_cont
|
|
CLOB
|
|
创建人ID
|
Admin_ID
|
F
|
Nvarchar2(32)
|
|
创建人名称
|
Admin_name
|
F
|
Nvarchar2(100)
|
|
创建时间
|
Create_time
|
|
DATE
|
|
最后修改时间
|
Last_TIME
|
F
|
DATE
|
|
最后修改人
|
Last_update_admin
|
F
|
Nvarchar2(100)
|
|
备注
|
Back
|
|
Nvarchar2(2000)
|
|
标志字段
|
Flag
|
|
NUMBER
|
1=可用 0=删除
|
序列名称:SEQ_TEMPALTE_ID
最后
以上就是勤劳口红最近收集整理的关于利用servlet输出CSS的全部内容,更多相关利用servlet输出CSS内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复