首页 > 编程知识 正文

基于javaweb的dd文件(javaweb创建xml文件)

时间:2023-12-23 11:38:06 阅读:319283 作者:QDOJ

本文目录一览:

如何在JavaWeb程序中使用tld文件

 tld定义格式

?xml version="1.0" encoding="ISO-8859-1" ?  

!DOCTYPE taglib  

PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.2//EN"  

""  

  

taglib  

!--定义标签版本库--  

tlib-version1.0/tlib-version  

!--定义jsp版本库--  

jsp-version1.2/jsp-version  

short-nameCms Tag/short-name  

description!--标签描述---  

A simple appbase tag library  

/description  

tag  

  

namepage/name!--tag的名字--  

tag-classcom.cms.common.tag.PageTag/tag-class!--tag对应的java类的名字--  

body-contentempty/body-content  

  

!--关于body-content 有三个值可选;empty:标签体必须为空;jsp:标签由其他jsp元素组成比如标签中含有%=attributeName%的jsp元素,那么此时body-content的值就是实际attributeName传入的值;tagdependent:有标签解释不带jsp转换(这个深入的含义不太了解)如果想深入交流技术可以加群前面435中间416最后141组合到一起就可以找到了--  

  

attribute!---这里表示的是这个tag的一个参数--  

namecmsform/name!--这个参数的名字--  

requiredtrue/required!--是否是必填选项--  

rtexprvaluetrue/rtexprvalue!--这个参数的值是否可以写入,换句话说 就是这个参数是否可以动态赋值--  

/attribute  

  

/tag  

  

/taglib

2、定义Tag对应类

此类必须重写doStartTag以及doEndTag方法

/** 

 *  

 */  

package com.cms.common.tag;  

  

import javax.servlet.jsp.JspException;  

import javax.servlet.jsp.JspWriter;  

import javax.servlet.jsp.tagext.TagSupport;  

  

/** 

 * @author louisliao 

 * 

 */  

public class DemoViewTag extends TagSupport {  

    /** 

     *  

     */  

    private static final long serialVersionUID = 1L;  

    private String cmsform = "";      

    public String getCmsForm() {  

        return cmsform ;  

    }  

    public void setCmsForm(String cmsform ) {  

        this.cmsform = cmsform ;  

    }  

        /** 

     *  

     */  

    public DemoViewTag() {  

        // TODO Auto-generated constructor stub  

    }  

    public int doStartTag()  

    {  

        return super.SKIP_BODY;  

    }  

    public int doEndTag() throws JspException  

    {  

        JspWriter writer=pageContext.getOut();  

        try {  

            writer.print("这是我的标签示例br/"+"cmsform :"+this.cmsform);  

        } catch (Exception e) {  

            // TODO: handle exception  

            e.printStackTrace();  

        }  

        return super.EVAL_PAGE;  

    }  

}

3、在web.xml中加入taglib对应文件配置 如:

taglib  

taglib-uri;/taglib-uri  

taglib-location/WEB-INF/mytag.tld/taglib-location  

/taglib

示例:

定义myTag.tld标签文件

?xml version="1.0" encoding="utf-8"?  

!DOCTYPE taglib PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.1//EN"  

      ""  

taglib  

    tlibversion1.0/tlibversion  

    jspversion1.1/jspversion  

    shortnameMyJSPTag Library/shortname  

    uri;/uri  

    info我的示例标签库/info  

      

    tag  

        namedemo.Viewport/name  

        tagclasscom.myapp.web.tag.DemoViewTag/tagclass  

        bodycontentJSP/bodycontent  

        infodemo.Viewport标签/info  

        attribute  

            namenorthTitle/name  

            requiredtrue/required  

            rtexprvaluetrue/rtexprvalue  

        /attribute  

        attribute  

            namewestTitle/name  

            requiredtrue/required  

            rtexprvaluetrue/rtexprvalue  

        /attribute    

    /tag  

/taglib

定义标签类

/** 

 *  

 */  

package com.myapp.web.tag;  

  

import javax.servlet.jsp.JspException;  

import javax.servlet.jsp.JspWriter;  

import javax.servlet.jsp.tagext.TagSupport;  

  

/** 

 * @author louisliao 

 * 

 */  

public class DemoViewTag extends TagSupport {  

    /** 

     *  

     */  

    private static final long serialVersionUID = 1L;  

    private String northTitle = "";  

    private String westTitle = "";  

      

    public String getNorthTitle() {  

        return northTitle;  

    }  

    public void setNorthTitle(String northTitle) {  

        this.northTitle = northTitle;  

    }  

    public String getWestTitle() {  

        return westTitle;  

    }  

    public void setWestTitle(String westTitle) {  

        this.westTitle = westTitle;  

    }  

    /** 

     *  

     */  

    public DemoViewTag() {  

        // TODO Auto-generated constructor stub  

    }  

    public int doStartTag()  

    {  

        return super.SKIP_BODY;  

    }  

    public int doEndTag() throws JspException  

    {  

        JspWriter writer=pageContext.getOut();  

        try {  

            writer.print("这是我的标签示例br/westTitle:"+this.westTitle+"br/northTitle:"+this.northTitle);  

        } catch (Exception e) {  

            // TODO: handle exception  

            e.printStackTrace();  

        }  

        return super.EVAL_PAGE;  

    }  

}

web.xml添加配置

taglib  

taglib-uri;/taglib-uri  

taglib-location/WEB-INF/mytag.tld/taglib-location  

/taglib

测试页面

%@ page language="java" import="java.util.*" pageEncoding="utf-8"%  

%@ taglib uri="" prefix="myTag"%   

%  

String path = request.getContextPath();  

String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";  

%  

  

!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"  

html  

  head  

    base href="%=basePath%"  

      

    titleMy JSP 'tagtldDemo.jsp' starting page/title  

      

    meta http-equiv="pragma" content="no-cache"  

    meta http-equiv="cache-control" content="no-cache"  

    meta http-equiv="expires" content="0"      

    meta http-equiv="keywords" content="keyword1,keyword2,keyword3"  

    meta http-equiv="description" content="This is my page"  

    !-- 

    link rel="stylesheet" type="text/css" href="styles.css" 

    --  

  

  /head  

    

  body  

    This is my JSP page. br  

    myTag:demo.Viewport northTitle="南" westTitle="西"/myTag:demo.Viewport  

  /body  

/html

Javaweb项目中页面展示是用什么文件

使用jsp和html展示内容以及和后端交互。

html是静态页面,jsp是动态页面,日常开发中,这两种都是结合使用的。

JSP全名为JavaServerPages,中文名叫java服务器页面,其根本是一个简化的设计,它 是由Sun Microsystems公司倡导、许多公司参与一起建立的一种动态网页技术标准。JSP技术有点类似ASP技术,它是在传统的网页HTML标准通用标记语言的子集文件*.htm,*.html中插入Java程序段Scriptlet和JSP标记tag,从而形成JSP文件,后缀名为(*.jsp),用JSP开发的Web应用是跨平台的,既能在Linux下运行,也能在其他操作系统上运行。

java web 大文件上传下载

直接把大文件读取为IO流,之后进行上传下载即可,不用担心文件大,是可以分流下载上传的(setBufferSize(1024))。

举例:

import hkrt.b2b.view.util.Log;

import hkrt.b2b.view.util.ViewUtil;

import java.io.ByteArrayOutputStream;

import java.io.FileInputStream;

import java.io.FileOutputStream;

import java.io.InputStream;

import org.apache.commons.net.;

import org.apache.commons.net.;

public class CCFCCBFTP {

/**

* 上传文件

*

* @param fileName

* @param plainFilePath 明文文件路径路径

* @param filepath

* @return

* @throws Exception

*/

public static String fileUploadByFtp(String plainFilePath, String fileName, String filepath) throws Exception {

FileInputStream fis = null;

ByteArrayOutputStream bos = null;

FTPClient ftpClient = new FTPClient();

String bl = "false";

try {

fis = new FileInputStream(plainFilePath);

bos = new ByteArrayOutputStream(fis.available());

byte[] buffer = new byte[1024];

int count = 0;

while ((count = fis.read(buffer)) != -1) {

bos.write(buffer, 0, count);

}

bos.flush();

Log.info("加密上传文件开始");

Log.info("连接远程上传服务器"+CCFCCBUtil.CCFCCBHOSTNAME+":"+22);

ftpClient.connect(CCFCCBUtil.CCFCCBHOSTNAME, 22);

ftpClient.login(CCFCCBUtil.CCFCCBLOGINNAME, CCFCCBUtil.CCFCCBLOGINPASSWORD);

FTPFile[] fs;

fs = ftpClient.listFiles();

for (FTPFile ff : fs) {

if (ff.getName().equals(filepath)) {

bl="true";

ftpClient.changeWorkingDirectory("/"+filepath+"");

}

}

Log.info("检查文件路径是否存在:/"+filepath);

if("false".equals(bl)){

ViewUtil.dataSEErrorPerformedCommon( "查询文件路径不存在:"+"/"+filepath);

return bl;

}

ftpClient.setBufferSize(1024);

ftpClient.setControlEncoding("GBK");

// 设置文件类型(二进制)

ftpClient.setFileType(FTPClient.BINARY_FILE_TYPE);

ftpClient.storeFile(fileName, fis);

Log.info("上传文件成功:"+fileName+"。文件保存路径:"+"/"+filepath+"/");

return bl;

} catch (Exception e) {

throw e;

} finally {

if (fis != null) {

try {

fis.close();

} catch (Exception e) {

Log.info(e.getLocalizedMessage(), e);

}

}

if (bos != null) {

try {

bos.close();

} catch (Exception e) {

Log.info(e.getLocalizedMessage(), e);

}

}

}

}

/**

*下载文件

*

* @param localFilePath

* @param fileName

* @param routeFilepath

* @return

* @throws Exception

*/

public static String fileDownloadByFtp(String localFilePath, String fileName,String routeFilepath) throws Exception {

FileInputStream fis = null;

ByteArrayOutputStream bos = null;

FileOutputStream fos = null;

FTPClient ftpClient = new FTPClient();

String SFP = System.getProperty("file.separator");

String bl = "false";

try {

Log.info("下载并解密文件开始");

Log.info("连接远程下载服务器"+CCFCCBUtil.CCFCCBHOSTNAME+":"+22);

ftpClient.connect(CCFCCBUtil.CCFCCBHOSTNAME, 22);

ftpClient.login(CCFCCBUtil.CCFCCBLOGINNAME, CCFCCBUtil.CCFCCBLOGINPASSWORD);

// ftpClient.connect(CMBCUtil.CMBCHOSTNAME, 2021);

// ftpClient.login(CMBCUtil.CMBCLOGINNAME, CMBCUtil.CMBCLOGINPASSWORD);

FTPFile[] fs;

ftpClient.makeDirectory(routeFilepath);

ftpClient.changeWorkingDirectory(routeFilepath);

bl = "false";

fs = ftpClient.listFiles();

for (FTPFile ff : fs) {

if (ff.getName().equals(fileName)) {

bl = "true";

Log.info("下载文件开始。");

ftpClient.setBufferSize(1024);

// 设置文件类型(二进制)

ftpClient.setFileType(FTPClient.BINARY_FILE_TYPE);

InputStream is = ftpClient.retrieveFileStream(fileName);

bos = new ByteArrayOutputStream(is.available());

byte[] buffer = new byte[1024];

int count = 0;

while ((count = is.read(buffer)) != -1) {

bos.write(buffer, 0, count);

}

bos.flush();

fos = new FileOutputStream(localFilePath+SFP+fileName);

fos.write(bos.toByteArray());

Log.info("下载文件结束:"+localFilePath);

}

}

Log.info("检查文件是否存:"+fileName+" "+bl);

if("false".equals(bl)){

ViewUtil.dataSEErrorPerformedCommon("查询无结果,请稍后再查询。");

return bl;

}

return bl;

} catch (Exception e) {

throw e;

} finally {

if (fis != null) {

try {

fis.close();

} catch (Exception e) {

Log.info(e.getLocalizedMessage(), e);

}

}

if (bos != null) {

try {

bos.close();

} catch (Exception e) {

Log.info(e.getLocalizedMessage(), e);

}

}

if (fos != null) {

try {

fos.close();

} catch (Exception e) {

Log.info(e.getLocalizedMessage(), e);

}

}

}

}}

备注:以上方法就实现了流的二进制上传下载转换,只需要将服务器连接部分调整为本地的实际ftp服务用户名和密码即可。

Java web开发项目中各文件的作用

JSP 所有的网页代码

js所有的javaScript代码

bo一般是java的类文件

dao一般是处理数据库方法的接口

impl是上述接口的实现

service 是 处理数据库逻辑的服务

action 是处理业务逻辑的

xml是配置文件

jsp得到请求到 structs的配置文件里找相应的配置方法,根据配置方法到action里找到处理的方法,然后执行,返回一个结果,再到刚才的配置文件里查找返回处理结果,然后返回jsp页面上

这其中,action里的处理的时候,可能会跟数据库发生交互,就会调用service里的方法,service里的方法又会通过接口调用impl里的方法,然后bo里是与数据库一一对应的映射文件,对应着数据库里的每张表

javaweb项目导出exce文件

java导出Excel需要用到poi的jar包,

// 第一步,创建一个webbook,对应一个Excel文件  

        HSSFWorkbook wb = new HSSFWorkbook();  

        // 第二步,在webbook中添加一个sheet,对应Excel文件中的sheet  

        HSSFSheet sheet = wb.createSheet("学生表一");  

        // 第三步,在sheet中添加表头第0行,注意老版本poi对Excel的行数列数有限制short  

        HSSFRow row = sheet.createRow((int) 0);  

        // 第四步,创建单元格,并设置值表头 设置表头居中  

        HSSFCellStyle style = wb.createCellStyle();  

        style.setAlignment(HSSFCellStyle.ALIGN_CENTER); // 创建一个居中格式  

  

        HSSFCell cell = row.createCell((short) 0);  

        cell.setCellValue("学号");  

        cell.setCellStyle(style);  

        cell = row.createCell((short) 1);  

        cell.setCellValue("姓名");  

        cell.setCellStyle(style);  

        cell = row.createCell((short) 2);  

        cell.setCellValue("年龄");  

        cell.setCellStyle(style);  

        cell = row.createCell((short) 3);  

        cell.setCellValue("生日");  

        cell.setCellStyle(style);  

  

        // 第五步,写入实体数据 实际应用中这些数据从数据库得到,  

        List list = CreateSimpleExcelToDisk.getStudent();  

  

        for (int i = 0; i  list.size(); i++)  

        {  

            row = sheet.createRow((int) i + 1);  

            Student stu = (Student) list.get(i);  

            // 第四步,创建单元格,并设置值  

            row.createCell((short) 0).setCellValue((double) stu.getId());  

            row.createCell((short) 1).setCellValue(stu.getName());  

            row.createCell((short) 2).setCellValue((double) stu.getAge());  

            cell = row.createCell((short) 3);  

            cell.setCellValue(new SimpleDateFormat("yyyy-mm-dd").format(stu  

                    .getBirth()));  

        }  

        // 第六步,将文件存到指定位置  

        try  

        {  

            FileOutputStream fout = new FileOutputStream("E:/students.xls");  

            wb.write(fout);  

            fout.close();  

        }  

        catch (Exception e)  

        {  

            e.printStackTrace();  

        }  

    }

基于ssh框架的javaweb项目配置文件都有哪些?

三大框架需要用到的配置文件总共有一下几个:struts.xml、hibernate-cfg.xml 、spring.xml 、web.xml。添加了配置文件其实只是其中的一个步骤,第二步,应该添加各个框架的jar包(添加需要用到的就行)。 这样,三个框架的环境才算配置完成。

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。