利用servlet输出CSS

1 篇文章 0 订阅
一、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
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值