Struts 1 upload large file validation - java

I have a problem with uploading a large file (>max_upload_size). Why all form fields are null (when uploading this file) in form validate method?
I tried to manage this by asking if file is null and return action error if so, and while debugging seems ok, i get no response to my browser. I have already managed this on another project. This former project worked on Bea web server, while this current is on Jboss.

Can you post the what your jsp looks like.
Also do not forget to include this (enctype="multipart/form-data") in your jsp form definition:
<html:form action="/uploadme" enctype="multipart/form-data">
<html:file property="myfileToupload"/>
</html:form>

Related

Tomcat 404 when using servlets

So I am currently trying to test a project whose facets I have changed, namely, I added a dynamic web component to it. In order to do so I decided to do a basic html form, and associated servlet with it.
However, when I try to run it I get a 404. Interestingly enough, a project I had which worked fine today is now also facing a similar issue. Though my practice servlet, which is used a template for everything else, does not have this issue.
the form follows this format:
<form action="myServlet">
<input type = "submit"/>
</form>
the servlet simply returns a writer.println("Hello World");
Error message:
HTTP Status 404 - /userName/LoginServlet
type Status report
message /userName/LoginServlet
description The requested resource is not available.
Apache Tomcat/8.0.38
Edit, and now the one servlet that worked also stopped working throwing the same error. If it helps, I am trying to run it from eclipse, by right clicking on my html page and then selecting for it to run on my server.
Problem was rather simple to hidden, since the name was refactored, the servlet mapping in eclipse did not show this. Deleting and recreating the servlet fixed it.
At least for now.

Error in loading a pdf file stored inside the web application

Problem:
I have a number of pdf files saved in the resources folder of my web app. When I try to display the file in the jsp I am not able to. Below is the code snippet:
jsp file:
<input type="hidden" id="myResourceFile" value="<%=request.getServletContext.getRealPath("/resources/myattmts/")%>"/>
<div id="myrowid">
<embed TYPE="application/pdf" align="middle" width=100% style="height:400px" id="pdfDoc"/>
</div>
javascript code:
document.getElementById("pdfDoc").src=$('#myResourceFile').val()+"'\'"+filename;
Error:
The pdf does not load as the file source delimiter '\ is not evaluated correctly.
Any help where I am going wrong
I am testing the web application in my locally. However it is to be deployed over a particular node after build and release.
The problem here was that the pdf file is retrieval only from the application context inside a jsp.
However when I use request.getServletContext.getRealPath("/resources/myattmts/") it tries to access the actual war file in the tmp/deployment server (the actual physical location where the application is running and the file is present). And is not able to read it from there.
Instead I changed the value of the hidden variable "myResourceFile" in the jsp to the application context path as
jsp change:
<input type="hidden" id="myResourceFile" value="<%=request.getContextPath("/resources/myattmts/")%>"/>
So the file path now reads as "`http://localhost:8080/app-name/resources/myattmts/fileName.pdf"
instead of the actual physical path (in the previous case which was not accessible to the jsp)
as "E:/MyServer/deployments/tmp/app.war/resources/myattmts/fileName.pdf"

How to know which is the JSP webpage that is showing my servlet

I have a project that I can see the JSP's... However Jboss shows me the servlets so in the address bar all i can see is:
"appservleer?=AppDev"
This is an example not the actual address...but with that info only how can I know which JSP is being displayed at that moment by JBoss.
or am I understanding this Jboss, servlet, JSP incorrectly?
Some guidance would be appreciated.
Thanks.
You cannot know which jsp is being displayed unless the developer decided to give hints about it.
A jsp is just a view technology that the servlet uses to render a response. That is, typically, the jsp will be parsed and html will be generated. However, the developer of the servlet may decide to write to the response himself. So nothing can really tell you if what you got came from a jsp or from another source, even if you had a url like www.mydomain.com/page.jsp. Nothing guarantees the response you are seeing in your browser was generated from a jsp.
The only way to know for sure which JSP is used for rendering is to look at the source code of the servlet that is mapped under (in your example) "appservleer".
Look in web.xml which servlet is mapped with this path, and open the source code of this servlet. Then figure out the execution path, starting with the doGet(...) or the doPost(...) method, and see to which JSP it is forwarded in the end...
Good luck.
You should always start with the web.xml file which will eventually lead you to the actual jsp file that is displayed. Start with the servlet mapping and check which servlet is invoked for the url. Then dig into the servlet to find out which jsp it is redirected to. If you are using any application framework then look for the implementation to findout the mapping. For e.g. in spring the spring configuration files or the controller classes tells you where the calls are redirected to.

How to call one portlet from another portlet in Liferay?

I have created 3 portlets (testimonial portlet, directory portlet, polling portlet), and I want to call testimonial portlet from directory portlet. How to do this? Kindly help me.
I have written the following code in my view.jsp file of directory portlet:
<%# taglib uri="http://liferay.com/tld/portlet" prefix="liferay-portlet" %>
<liferay-portlet:renderURL var="linkURL" portletName="testi" windowState="maximized" />
<br>
Testimonial
I can redirect in another page, but I got error like
This portlet has been undeployed. Please redeploy it or remove it from
the page.
Should I make changes in liferay-portlet.xml? Kindly help me.
portletName attribute value , you specified seems incorrect.
Thats the reason, you are getting that message.
I just checked giving incorrect name "test" as portletName whereas there isnt any portlet with name test.
If <portlet-name>test</portlet-name> is the entry in your liferay-portlet.xml ,
then give portletName as test_WAR_testportlet, it will work.
If other portlet is Liferay's Out of Box portlet, you can utilize PortletKeys class.
HTH
I had same requirement. But i am very new in Liferay...
So i have not much more knowledge of Liferay API.
So I used web service for fetch portlet data to another portlet. Its really interesting and very easy..
You can find more help from this.
Jersey RestFul webService
I done this and all working very well.
Thankssssss

glassfish 3 Error 404

My site transforms an XML to HTML pages. Inside "Web Pages" folder I've create a folder "acces" that will contain the generated HTML pages and the images used inside. The generating process works, it places the files HTML and jpg, in the corect format in the folder acces. I can acces them from my local disk. When I try to acces the jpg at localhost:8080/myapp/acces/img/Image1.jpg, it works, but when I access localhost:8080/myapp/acces/img/someHtml.html it returns error 404.
If I open the file, from that folder, with that specific name: someHtml.html directly with a browser, it works.
What should I do to make the page become visible. I want to use it inside an HTML iframe.
I think what might be happening in your situation is that your Glassfish is likely deploying your application in a WAR archive, and what happens is your application might be writing to where your code is contained (wherever your workspace might be) so it won't be accessible from the application which is currently running off the WAR file you previously generated. Glassfish has likely already loaded up your application from the WAR file into memory and won't see the new files you've created until you rebuild and redeploy
What you might need to do is write it to some folder, and perhaps have a servlet that will retrieve the file and send it to client. That to me isn't the most elegant solution, you could just use a HTTP Server in front of the glassfish (apache or nginx or whatever) read the generated HTML file
Solved!
In my case I joust corrected:
<form action="mServlet" method="post">
<input type="text" name="variable1"/>
<input type="text" name="variable2"/>
<input type="submit" name="btnBoton"/>
</form>
It was misspeled:
miServlet --> mServlet

Categories

Resources