Read contents of uploaded HTML file to string in JAVA - java

I need to upload an HTML file using a servlet and put its contents in a string. The request comes in multi-part/form-data.
I am trying to use Part filepart = request.getPart("file") but that's not working. I need to know if there is anyway to achieve this without using third party APIs like Apache Commons FileUploader.

Related

Generate HTML file using JSP template

How is it possible to generate HTML file using Servlet/JSP?
I'm using Spring MVC to create a service. This service would get some data from the database. Then I'd like it to read a JSP template from somewhere else, not from WEB-INF. There are attributes which are the data from the database that would be passed in upon reading this template. Then it should return a string which includes the source of JSP. This string should now contain the data which replaces the JSP variables. Finally, this string should be written to a file (.html file).
I can't find a tutorial about it. Instead, i noticed mostly the JSP file is being dispatched as response and displayed on the browser.
Please help. Thannks.
You can use spring with Thymeleaf.
Thymeleaf is a Java-based library used to create a web application. It provides good support for serving an XHTML/HTML5 in web applications. In this chapter, you will learn in detail about Thymeleaf.
Tutorial from Thymeleaf:- click here

Read a JSON or XML file in a JSP page and pass to Spring controller

I have an application which needs to read contents of a JSON or XML file and then send the JSON or XML to a Spring controller so that data can be processed. I'm not really sure where to start with this. I don't believe it is possible to send the file itself to the controller (uploading it but not saving it on the server). What would be the best approach?
Solved by using ajaxSubmit.
Over-rode the submit functionality of the form using ajaxSubmit which then uploaded a MultiPart file object to the controller. This can then be turned into a temporary file on the server and processed.

How to save fetched html content to database in apache nutch?

I'm using 1.8 version of apache nutch. I want to save crawled HTML content to postgre database to do this, I modify FetcherThread.java class as below.
case ProtocolStatus.SUCCESS: // got a page
pstatus = output(fit.url, fit.datum, content, status,
CrawlDatum.STATUS_FETCH_SUCCESS, fit.outlinkDepth);
updateStatus(content.getContent().length);
/*Added My code Here*/
But I want to use plug-in system instead of directly modifying FetcherThread class. To use plug-in system which extension points I need to use?
You could write a custom plugin and implement an extension of org.apache.nutch.indexer.IndexWriter to send the documents to
Postgres as part of the indexing step. You'll need to index the raw content which requires NUTCH-2032 - this is in Nutch 1.11 so you will need to upgrade your version of Nutch.
Alternatively you could write a custom MapReduce job which would take a segments as input, read the content and send it to your DB in the reduce step.

Save GXT Tree to XML file in Java

How to save GXT Tree content (com.extjs.gxt.ui.client.widget.tree.Tree) to a XML file in Java?
Quid Pro Quo. A less detailed answer would be as follows
You would be anyway using a List of Lists via Store or DataProviders. Send them to server by Serializing them over RPC or JSON via RequestBuilder. Use a XML library to convert them to XML file on the run and in the on success call of rpc/request builder give a url to download the xml file if required.
Note - This can be done any number of ways depending on the details of your requirement and your expertise!!!!

Validation of files uploaded to the server

In my web application I need to upload file to the server. This file is JasperReport template and its extension is .jrxml. So I want to make that server accepts files only with this extension. To upload file I'm using ServletFileUpload. To verify file extension I'm only verifying if fileName contains ".jrxml". But I don't feel that this method is secure enough. Is there any possibility to make upload more safe ?
You can use XML Validator to verify the uploaded file against the Jasper Report XSD. If you wanted to go the additional step you could also compile the uploaded template using the JasperCompile though that might be overkill for your app and a drag on performance.

Categories