html和java怎么连起来,java拼接html
java可以与html结合到一块吗
可以的 在需要加交互效果的盒子(以div为例)后面加script标签
div
内容
/div
script
正常的JavaScript代码
/script

怎么把html 和java联系起来
首先你的思想就是错的,java是java,javascript是javascript,两者是完全不同的语言,不可混为一谈,也不可互相转换。
网页程序是分为两部分的,客户端页面与服务器端后台,前者使用html+javascript,后者使用java或asp,泾渭分明,只有通过页面提交或ajax方式才可以通信,其他的时候都是各管个的,不相往来的。你所说的把java嵌入到网页中这个想法本身就是错的。最好重新考虑一下需求,哪些是要放在前台,哪些放在后台,划分清楚后再分别实装。
用Java怎么连接一个Html网页?
将以下代码保存为 Test.java 即可运行(界面挫了点,不过核心功能都有,你可以自己拿回去改改界面就可以了)
package com;
import javax.swing.*;
import java.awt.BorderLayout;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
public class Test extends JFrame{
public static void main(String args[]){
new Test();
}
JTextField ieField;
JButton button;
public Test(){
super("单击按钮打开一个网页");
ieField = new JTextField("",30);
button = new JButton("打开 IE 网页");
button.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent event){
try{
Process process = Runtime.getRuntime().exec("cmd.exe /C start iexplore " + ieField.getText());
}catch(Exception e){
e.printStackTrace();
}
}
});
this.getContentPane().setLayout( new BorderLayout());
this.getContentPane().add(ieField,BorderLayout.CENTER);
this.getContentPane().add(button,BorderLayout.SOUTH);
this.setSize(600,200);
this.setVisible(true);
}
}
散分吧 赚点小分真不容易....
如何吧html语言嵌套在java中
应该是把java代码嵌入到 html 中 jsp: %@ page language="java" import="java.util.*" pageEncoding="utf-8"% % 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 'buy.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 % request.setCharacterEncoding("utf-8"); String productName=request.getParameter("productName"); int productNum=Integer.parseInt("productNum"); Object obj=session.getAttribute(productName); if(obj!=null){ int oldNum=((Integer)obj).intValue(); productNum+=oldNum; session.setAttribute(productName, productNum); }else{ session.setAttribute(productName, productNum); } % 购物成功 a href="show.jsp"查看购物车/a a href="index.jsp"继续购物/a % % /body /html 不能实现功能哈 只是给你看看结构
希望采纳