다시 나입니다.) 또 다른 문제가 있습니다. 웹에서 파일 (예 : -xtxt)을로드하고 싶습니다. 내 관리 빈의 다음 코드를 사용하려고 :인터넷에서 내 jsf 앱으로 txt 파일을로드하려면 어떻게해야합니까?
public void run()
{
try
{
URL url = new URL(this.filename);
URLConnection connection = url.openConnection();
bufferedReader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
if (bufferedReader == null)
{
return;
}
String str = bufferedReader.readLine();
while (bufferedReader.readLine() != null)
{
System.out.println("---- " + bufferedReader.readLine());
}
}
catch(MalformedURLException mue)
{
System.out.println("MalformedURLException in run() method");
mue.printStackTrace();
}
catch(IOException ioe)
{
System.out.println("IOException in run() method");
ioe.printStackTrace();
}
finally
{
try
{
bufferedReader.close();
}
catch(IOException ioe)
{
System.out.println("UOException wile closing BufferedReader");
ioe.printStackTrace();
}
}
}
public String doFileUpdate()
{
String str = FacesContext.getCurrentInstance().getExternalContext().getRequestServletPath();
System.out.println("111111111111111111111 str = " + str);
str = "http://narod.ru/disk/20957166000/test.txt.html";//"http://localhost:8080/sfront/files/test.html";
System.out.println("222222222222222222222 str = " + str);
FileUpdater fileUpdater = new FileUpdater(str);
fileUpdater.run();
return null;
}
그러나 BufferedReader로 내가 관리 빈의 메소드를 호출하는 것을 시도하고 현재 페이지의 HTML 코드를 반환합니다. 그것은 매우 이상한 일입니다. 저는 봤는데 아무도이 문제가 없었습니다.
어쩌면 내가 뭔가 잘못했는지, 아마도 net API를 사용하지 않는 웹 (jsf) 앱에 파일을로드하는 가장 간단한 방법이있을 수 있습니다. 어떤 아이디어?
도움 주셔서 대단히 감사드립니다.
업데이트 :
어쩌면 일부 JSF 코드가 도움이 될 것입니다 :
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:a4j="http://richfaces.org/a4j"
xmlns:rich="http://richfaces.org/rich"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:fc="http://www.fusioncharts.com"
xmlns:t="http://myfaces.apache.org/tomahawk"
template="template.xhtml">
<ui:define name="title">Add company page</ui:define>
<ui:define name="content">
<h:form id="addCompanyForm">
<h:outputText value="Add a new company"/><br/><br/><br/>
<div style="width: 400px;">
<table width="100%" cellpadding="0" cellspacing="0">
<tr>
<td width="1">
Company name:
</td>
<td>
<h:inputText id="companyName" value="#{companyBean.companyName}" style="width: 100%;" required="true" />
</td>
</tr>
<tr>
<td valign="top" nowrap="nowrap">
Company description: 
</td>
<td>
<h:inputTextarea value="#{companyBean.companyDescription}" style="width: 100%;"/>
</td>
</tr>
</table><br/>
<center>
<h:commandButton value="Save company" action="#{companyBean.doInsertCompany}" style="width: 40%;"/>  
<a4j:commandButton ajaxSingle="true" value="Clear" actionListener="#{companyBean.doClear}" style="width: 40%;" reRender="addCompanyForm"/>
</center>
<br/><br/><br/>
<h:commandLink value="Return to companies page" action="companies" immediate="true" />
</div>
</h:form>
<h:form>
<br/>
<h:commandButton value="File Update" action="#{companyBean.doFileUpdate}" style="width: 10%;"/>  
</h:form>
</ui:define>
</ui:composition>
업데이트 2 : 나는 (로컬 호스트되지 않음) 웹에서 다른 파일을 - 모든 것이 잘 작동! 이것에 대해 미안하다))))
BalusC가 말했듯이, 내 앱은 단지 URL : http://localhost:8080/sfront/files/test.txt로 파일을 찾지 못했습니다.
로컬 파일을 사용할 수없는 이유를 알지 못합니다.
아이디어가 있으십니까?
당신은 몇 가지 코드를 형식화하는 필요 ... – mosg
나는 몇 가지 코드를 포맷. @ 엘레나 : 메시지를 편집하는 동안 오른쪽 열의 서식 규칙에주의를 기울여야하며 페이지 하단의 미리보기 섹션을 사용하여 모든 것이 잘 보이는지 확인하십시오. – BalusC
도와 주셔서 감사합니다.))) 어떤 코드를 만들었습니까? 내 브라우저 (Opera 10.53)에서는 모든 것이 잘 보입니다. 소스 코드의 경우 4 칸 (더 많은)을 수행합니다.당신은 나에게 무엇을 잘못 말했고 어떻게 해결할 수 있습니까? – Elena