资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

JAVA网页代码生成 java怎么制作网页

java中如何根据一个网址获得该网页的源代码?

package test;

我们提供的服务有:网站设计制作、成都网站设计、微信公众号开发、网站优化、网站认证、交口ssl等。为1000+企事业单位解决了网站和推广的问题。提供周到的售前咨询和贴心的售后服务,是有科学管理、有技术的交口网站制作公司

import java.io.BufferedReader;

import java.io.InputStreamReader;

import java点虐 .HttpURLConnection;

import java点虐 .URL;

public class HttpTest {

private String u;

private String encoding;

public static void main(String[] args) throws Exception {

HttpTest client = new HttpTest("", "UTF-8");

client.run();

}

public HttpTest(String u, String encoding) {

this.u = u;

this.encoding = encoding;

}

public void run() throws Exception {

URL url = new URL(u);// 根据链接(字符串格式),生成一个URL对象

HttpURLConnection urlConnection = (HttpURLConnection) url

.openConnection();// 打开URL

BufferedReader reader = new BufferedReader(new InputStreamReader(

urlConnection.getInputStream(), encoding));// 得到输入流,即获得了网页的内容

String line; // 读取输入流的数据,并显示

while ((line = reader.readLine()) != null) {

System.out.println(line);

}

}

}

根据具体问题类型,进行步骤拆解/原因原理分析/内容拓展等。

具体步骤如下:/导致这种情况的原因主要是……

用java做B/S企业应用开发。我可以用dreamweaver生成网页,然后直接生成jsp代码么?

可以生成,不过需要安装IIS再进行服务器配置才能在浏览器中打开。推荐使用eclipse进行jsp动态网页制作,可以先在dreamweaver里制作静态网页,再将其导入eclipse修改后缀后添加动态代码(在eclipse中是方便调试,环境也可以在软件中直接配置)

如何使用Freemarker生成java代码

Freemarker是一个模板框架。我们可以通过Freemarker进行代码生成或页面的静态生成。 现在简单的说一下怎样使用Freemarker Freemarker的主要生成类

public boolean generate(String templateFileName, Map data,

String fileName) {

try {

//取得模板的位置

String templateFileDir=templateFileName.substring(0, templateFileName.lastIndexOf("/"));

//取得模板的名字

String templateFile=templateFileName.substring(templateFileName.lastIndexOf("/"), templateFileName.length());

//取得生成文件的路径

String genFileDir=fileName.substring(0, fileName.lastIndexOf("/"));

Template template = ConfigurationHelper.getConfiguration(templateFileDir).getTemplate(templateFile);

File fileDir=new File(genFileDir);

org.apache点抗 mons.io.FileUtils.forceMkdir(fileDir);

File output = new File(fileName);

if(output.exists()){

//如何代码已存在不重复生成

return false;

}

Writer writer = new FileWriter(output);

template.process(data, writer);

writer.close();

} catch (TemplateException e) {

e.printStackTrace();

return false;

} catch (IOException e) {

e.printStackTrace();

return false;

}

return true;

}

代码中的Map 是模板所需要的数据,我们可以通过面向对像的方法把数据存在模板中public boolean genDaoInterface(String fileName){

DaoModel daoModel=new DaoModel();

//设置Dao实现类的包名

daoModel.setPackageName(DaoConstant.PACKAGE);

//取得接口名

String className=StringUtils.substringBefore(fileName,".");

//设置接口名

daoModel.setClassName(className);

MapString, Object data = new HashMapString, Object();

data.put("model", daoModel);

//设置生成的位置

String filePath=new String("src/"+package2path(DaoConstant.PACKAGE)+"/"+fileName);

//代码生成

return super.generate(DaoConstant.INTERFACE_TEMPLATE, data, filePath);

}

data.put("model", daoModel);由这句代码可看出我们将可以在模板中直接调用这些数据package ${model.packageName};

public interface ${model.className} extends BaseHibernateDao {

}

JAVA动态生成HTML代码

freemarker没有功能。freemarker要求你自己把东西取出来放到request的attribute里面,然后在ftl文件中使用那些attribute。

可以自己用Java反射来得到实体中字段,然后自己拼html字符串


标题名称:JAVA网页代码生成 java怎么制作网页
URL标题:http://cdkjz.cn/article/ddjoics.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

大客户专线   成都:13518219792   座机:028-86922220