JAVA里能插入HTML代码吗?怎么编写啊,当我加入 out.println时,老报错,是怎么回事?

如题所述

第1个回答  2013-02-05
当然可以了。只是你的Html是不带弹出框的标签的吧。反正我没见过。都是js的 。。。你用out.println报错。我估计是你没有new out的对象。。你要用打印流来new 出 out的对象。
第2个回答  2013-02-05
JSP里面 <% %>写java代码,html代码直接写就行了啊。如果是动态(需要查询数据库)生成的,那么使用<%= %>就行了。
你参考下,不知道有没有记错。
一般out.println()都不用追问

我是想在JAVA类里编写HTML代码,能行吗?我是想在运行错误是弹出一个警示框!能行吗?

追答

可以啊,你要真的学会的话,建议你去学习下javascript基本语法,半天就够了。不然在这边问的话学不到什么

追问

File ff=con.DateDerived(request);
if(ff==null){
out.println("alert('没有上传文件,请上传文件!'); window.location='index.jsp' ");
}
就是想弹出这个?怎么实现啊?

追答

out.println用的很少 ,我试下。

追问

能行了嘛?

本回答被网友采纳
第3个回答  2013-02-05
可以在异常捕获的地方,调用swing用户界面组件
第4个回答  2013-02-05
System.out.print("hahahaha")追问

我是想在JAVA类里编写HTML代码,能行吗?我是想在运行错误是弹出一个警示框!能行吗?

追答

你可以参照这个:http://zhidao.baidu.com/question/43734419.html

追问

File ff=con.DateDerived(request);
if(ff==null){
out.println("alert('没有上传文件,请上传文件!'); window.location='index.jsp' ");
}
就是想弹出这个?怎么实现啊?

追答

---------------------------------------------------
File ff=con.DateDerived(request);
if(ff==null){
out.println("alert('没有上传文件,请上传文件!'); window.location='index.jsp' ");
}
---------------------------------------------------

以上代码中,把
out.println("alert('没有上传文件,请上传文件!'); window.location='index.jsp' ");
改为:
strAlert="alert('没有上传文件,请上传文件!'); window.location='index.jsp' ")

把strAlert定义为Public String 默认值为空字符串,然后,在jsp中用

追问

但是strAlert在我这里报错啊?是怎么回事,大侠

追答

在类开始时,添加 public String strAlert="";

例子:
解决了没?我做了个例子:
Tclass.java 代码(我把Tclass.java 建在名为TP的包中):
package TP;
public class Tclass {
public String aa="alert(1)";
}
test.jsp 代码:

Insert title here

直接运行jsp就行

第5个回答  2013-02-05
一般是html里插入java代码吧追问

File ff=con.DateDerived(request);
if(ff==null){
out.println("alert('没有上传文件,请上传文件!'); window.location='index.jsp' ");
}
就是想弹出这个?怎么实现啊?