【发布时间】:2016-12-09 02:52:18
【问题描述】:
我在一个名为 Jahia 的 CMS 上工作,我正在尝试显示 XML 列表中的文件列表,其中包含调用 Actions 的按钮来显示文件。
<Files>
<CdFile>
some info about the file path , filename ...
</CdFile>
<CdFile>
some info about the file path , filename ...
</CdFile>
<CdFile>
some info about the file path , filename ...
</CdFile>
</Files>
它在 mozilla 浏览器上运行良好,但在 Internet Explorer 上显示列表,但里面的按钮不起作用。任何想法 ?我认为问题出在列表上,也许 IE 不像其他浏览器那样使用它
<!DOCTYPE html>
<%@ taglib prefix="jcr" uri="http://www.jahia.org/tags/jcr" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%@ taglib prefix="utility" uri="http://www.jahia.org/tags/utilityLib" %>
<%@ taglib prefix="template" uri="http://www.jahia.org/tags/templateLib" %>
<%@ taglib prefix="functions" uri="http://www.jahia.org/tags/functions" %>
<jsp:useBean id="displayList" class="org.jahia.modules.connect.displayList" scope="request">
<jsp:setProperty name="displayList" property="userID" value="10" />
</jsp:useBean>
<form action="<c:url value='${url.base}${currentNode.path}.Connect.do'/>" method="post" id="ContactForm" enctype="multipart/form-data">
</form>
<table id="table_id" class="display" width="100%" cellspacing="1" cellpadding="0" border="1" align="left" bgcolor="#999999">>
<caption> Files of current user</caption>
<thead>
<tr>
<th>Download</th>
<th>Directory</th>
<th>file Name</th>
<th>document type</th>
<th>Date</th>
</tr>
</thead>
<tbody>
<c:forEach items="${displayList.test}" var="CdFile">
<tr>
<td><button name="subject" form="ContactForm" type="submit" value="${CdFile.path}">Download</button></td>
<td>${CdFile.folder}</td>
<td>${CdFile.fileName}</td>
<td>${CdFile.docType}</td>
<td>${CdFile.date}</td>
</tr>
</c:forEach>
</tbody>
</table>
我已经硬编码了 userID 的值用于测试
调用javabean读取XML然后创建文件列表
public class displayList{
private String userID;
private String pathToXML = "C:\\Users\\adm_fjousse\\Desktop\\serviceWin$test\\CnD_1000\\" ;
FileList fileList = new FileList();
private List<CdFile> test = new ArrayList<CdFile>();
public void setUserID(String userID){
this.userID = "ID"+ userID;
this.pathToXML = this.pathToXML + this.userID + ".xml";
startSocket();
}
public String getUserID(){
return this.userID;
}
public List<CdFile> getTest(){
return this.test;
}
public void startSocket(){
BufferedReader in;
PrintWriter out;
XStream xStream = new XStream();
ByteArrayOutputStream baos = new ByteArrayOutputStream() ;
String xml = "";
try{
//D'abord le client se connecte et attend un message.
Socket sock = new Socket(InetAddress.getByName("10.232.12.6"),2008);
in = new BufferedReader (new InputStreamReader (sock.getInputStream()));
//String message_distant = in.readLine();
System.out.println("1================================");
//Puis il dit qui il est
out = new PrintWriter(sock.getOutputStream());
out.println(userID);
out.flush();
//Ensuite le serveur va lui envoyer le fichier correspondant en fonction de son ID
transfert(sock.getInputStream(),baos, true);
System.out.println("size ===="+ baos.size());
System.out.println(userID);
xml =baos.toString("UTF-8");
xStream.alias("CdFile", CdFile.class);
xStream.alias("files", FileList.class);
xStream.addImplicitCollection(FileList.class, "fileList");
System.out.println("2================================"+ xml);
this.fileList = (FileList)xStream.fromXML(xml);
System.out.println(fileList);
this.test = fileList.getFileList();
System.out.println("3================================");
sock.close();
}
catch(Exception e){
e.getMessage();
}
}
public static void transfert(InputStream in , OutputStream out, boolean closeOnExit ) throws Exception{
try{byte buf[] = new byte[1024];
int n;
while((n=in.read(buf))!=-1){
System.out.println("============loop");
out.write(buf,0,n);
out.flush();
}
out.close();
}
catch(Exception e){
e.getMessage();
}
}
}
有调用显示文件的Action,当有onclick调用时:
public class Connect extends Action{
@Override
public ActionResult doExecute(HttpServletRequest req, RenderContext renderContext, Resource resource,
JCRSessionWrapper session, Map<String, List<String>> parameters,
URLResolver urlResolver) throws Exception{
System.out.println("11212================================");
HttpServletResponse r = renderContext.getResponse();
BufferedReader in;
PrintWriter out;
System.out.println("first================================");
String fileToSend = parameters.get("subject").get(0);
System.out.println(fileToSend);
System.out.println("1================================");
try{
//D'abord le client se connecte et attend un message.
Socket sock = new Socket(InetAddress.getByName("10.232.12.6"),2008);
in = new BufferedReader (new InputStreamReader (sock.getInputStream()));
//String message_distant = in.readLine();
//System.out.println(message_distant);
//Puis il dit qui il est
System.out.println("1================================");
out = new PrintWriter(sock.getOutputStream());
out.println(fileToSend);
out.flush();
System.out.println("2================================");
//Ensuite le serveur va lui envoyer le fichier correspondant en fonction de son ID
transfert(sock.getInputStream(),r.getOutputStream(), true);
renderContext.setResponse(r);
System.out.println("3================================");
sock.close();
}
catch(Exception e){
e.getMessage();
}
return new ActionResult(HttpServletResponse.SC_OK, null, new JSONObject());//,null, generateJSONObject(clientNode));
}
public static void transfert(InputStream in , OutputStream out, boolean closeOnExit ) throws Exception{
try{byte buf[] = new byte[1024];
int n;
while((n=in.read(buf))!=-1){
out.write(buf,0,n);
System.out.println("4================================");
out.flush();}
}
catch(Exception e){
e.getMessage();
}
}
}
服务器端类
public class ClientService extends Thread
{
Socket sockClient;
/*******************************************/
public ClientService(Socket client)
{
sockClient = client;
start();
}
/*******************************************/
public void run()
{
try
{
BufferedReader in = new BufferedReader(new InputStreamReader(sockClient.getInputStream()));
//PrintStream out = new PrintStream(sockClient.getOutputStream());
String distantMsg = in.readLine();
if(distantMsg.contains("ID") && distantMsg.length() < 15) {
String fileToSend = "C:\\Users\\adm_fjousse\\Desktop\\output\\"+ distantMsg +".xml";
Commun.transfert(new FileInputStream(fileToSend),
sockClient.getOutputStream(),
true);
}
else{
String fileToSend = distantMsg;
Commun.transfert(new FileInputStream(fileToSend),
sockClient.getOutputStream(),
true);
/*out.println("service running : "+(new Date()));
out.flush();
out.close();*/
}
}
catch(Exception ex) {}
try
{
sockClient.close();
}
catch(Exception ex) {}
sockClient = null;
}
}
class Commun{
public static void transfert(InputStream in , OutputStream out, boolean closeOnExit) throws IOException{
byte buf[] = new byte[1024];
int n;
while((n=in.read(buf))!=-1){
out.write(buf,0,n);
out.flush();
}
if(closeOnExit){
in.close();
out.close();
}
}
}
[my fina
我用Mozilla查看作品]1
【问题讨论】:
-
由于 JSP 不是在浏览器上读取的,这不是从那里来的,JSP 是在你的应用服务器上读取的。
-
@AxelH 是的我知道,但是服务器处理后按钮和动作会一样
-
所以这是一个 Javascript / JQuery 问题,
jsp标记在这里无关紧要(如标题引用 JSP) 这是 Internet Explorer 的 javascript 或 HTML 问题。浏览器的控制台有错误吗? -
对于没有服务器端设置和可用数据的任何人来说,这仍然无法重现。向我们展示一个可测试的实时版本 - jsfiddle 或其他东西。也请阅读minimal reproducible example。
-
为什么您的表单结束标记紧跟在表单开始标记之后,而不是在应该(大概)在其中的表单控件之后?
标签: html forms internet-explorer button browser