I am developing a evaluation system. I have set up a dynamic web project in eclipse (with apache tomcat) and have been able to successfully access and view project when accessing it on my local host. However, I just deployed it online (via a war) and when I access the site the web pages do not render. All that is shown is the code. I set the doc type and the content type in an html comment and a meta tag respectively. Why could this be happening? the site is deployed at (REMOVED) as of right now.
Firebug is a great tool to check the HTTP request/responses. Check the Net tab. Here are the HTTP response headers which I get when I access the site which you linked in the question:
Note the content type. It's wrong, it should be text/html. If you was using JSP to serve the response, then you probably had like this in top of your JSP
<%#page contentType="text/plain" %>
you should remove this (it already defaults to text/html) or if in vain, replace this by
<%#page contentType="text/html" %>
If still in vain, contact the support of your hosting.
Related
I have recently gone through Angular js tutorials. Directives are one of the pillar of AngularJS.
My understnading is directives can be good substitue of custom JSP tag libraies (which developers develop
specific to each project). Is that correct ?
The reason i am saying this JSP taglib are developed to have reusable ui component which can achieved by angularJs
directive that too on client side .
Yes you are absolutely correct. Angular js directives play the same role as Tag libraries in JSP. The only difference in JSP tags generated code on the server side and sent it to client whereas angular directives generate code on the client side
I've created a very basic portlet, which displays a String on-screen.
I have another web application hosted on separate VM which offers a REST api that I'd like to consume.
Understand I cannot make AJAX calls to remote web app (without some effort e.g proxy etc).
But what would be best approach to submitting HTTP GET requests to this remote web app?
I've considered both JSP and Servlets but not sure how to invoke the servlet from inside TestPortletView.xhtml and then display results?
Contents of TestPortletView.html ..
<%#page session="false" contentType="text/html" pageEncoding="ISO-8859-1" import="java.util.*,javax.portlet.*,com.ibm.test.*" %>
<%# taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet"%>
<%#taglib uri="http://www.ibm.com/xmlns/prod/websphere/portal/v6.1/portlet-client-model" prefix="portlet-client-model" %>
<portlet:defineObjects/>
<portlet-client-model:init>
<portlet-client-model:require module="ibm.portal.xml.*"/>
<portlet-client-model:require module="ibm.portal.portlet.*"/>
</portlet-client-model:init>
<DIV style="margin: 6px">
<H3 style="margin-bottom: 3px">Welcome!</H3>
This is my basic view mode page.<BR>
</DIV>
Project setup ..
From your code snippet, I'm assuming you're using Websphere Portal (the taglib uri). WebSphere Portal offers a feature called the Ajax Proxy. You can enable and configure the proxy to let you make cross domain requests through Portal. Essentially you send an AJAX request to the Portal that specifies the request you want to send to the other domain. Portal then sends that request on the browsers behalf and returns the response. From the browser's perspective you're only sending AJAX requests to the original domain.
The other option is modify your server with REST API to allow CORS. Here is an an existing answer on SO to give you an idea. The implementation will depend on how your REST service is implemented.
There are a few ways to do this:
Have your portlet make calls to the remote web service directly. Get the response, parse it and do what you need to it, then set the data via request.setAttribute (if its a view) or response.setRenderParameter (if its responding to an action) and your page can then display it. This is by far the easiest as your have fewer parts to manage.
Use a UI framework on the front end that allows for you to do AJAX calls (like jQuery). Then your HTML page can make requests to a servlet, that servlet can then do the work making the actual calls to the remote API and return a chunk of data in the response which your page can use. This would be the way to go if you had Java based logic that you needed the servlet to use (since your front end will only have Javascript to work with) AND you wanted it to be a bit more dynamic.
Also using a UI framework, if you don't have any Java based logic and can do it all in Javascript, then you can potentially have all of your logic in your front end code and just make requests to the remote app directly.
A same question can be found here . and some equal questions found.
They are about javascript (answer :-window.top.location.href = "http://www.site.com"; )
But
I want to know how to redirect it by Java in a jsp page. A usual redirect can be done as..
response.sendRedirect("newUrl.jsp");
But it redirects the source page inside the iframe not the parent page. The task is that the source file of the iframe get refreshed and do some stuff(checking session.. getting attributes. )and if the source page meets a particular logical stage,then the parent page might be redirected to another page.But not in javascript, I want to know it in JAVA( That means the jsp/servlet container decides and redirects to another page in the server).
My current opinion is that, such things might be handle with javascript.Your all info is highly appreciated.
Instead of sending a 301 or 302 redirect, send a JSP page (or write to the output stream of the response) with html content that has the javascript redirect in it set to execute on load. That way you can do your checking in the java side of things and just send the javascript redirect when appropriate, otherwise send regular content.
I have scenario like:
We have an application deployed on WebLogic and one application deployed on tomcat.
we have embeded tomcat application to run in WebLogic application.
somewhere we want to redirect the page on WebLogic application URL which is the parent application. for that if you use:
response.sendRedirect("newUrl.jsp") it will redirect to inner application URL(tomcat).
to resolve it I have used JavaScript for redirection
<%
boolean isRedirect = true // check if redirection required, I have made it true for testing
String redirectHomepage = "home.jsp";
if(isRedirect){
%>
<script type="text/javascript">
window.parent.location.href = "<%=redirectHomepage%>"
</script>
<%
return;
}
%>
I have created a servlet called dbConnect(return type Connection). In which i wrote the code to connect to the database. Now I am calling the dbConnect(<%Connection con=dbConnect.getConnection()%>) into the JSP file. Since JSP file will be in the client side is there any possibility that an hacker can hack the connection??
The larger question is whether or not this is a good thing to do.
My preference would be no scriptlet code in JSPs whatsoever. If you must write JSPs, I'd recommend using JSTL tags and a servlet to handle requests. Let a servlet sit between the JSP and the database and intercede on its behalf with the database. You can do authentication, input validation, binding, and routing in the servlet and let the JSP do what it was meant to do: display only.
If this JSP is intended for anything other than a single toy application, I'd recommend that you dig into model-2 web MVC using JSPs and servlets.
JSP files aren't on the client side. A JSP is compiled into a servlet so anything you feel safe doing in a servlet is just as safe in a JSP page. That code snippet inside of <% %> is turned into plain old java code. Your HTML is turned into a string that's spit out from the servlet back to the client.
So yes, it's fine.
I have converted my static website into Jease, through localhost:8080/cms, and I can access my website using the URL localhost:8080/index.html and from there I can browse around my entire website. What I am not sure about, how can I configure Jease to directly go to index.html page as soon as I type localhost:8080? Because once I make it globally available I want to make sure the index.html page is accessed through mywebsite.com URL.
Any hints would be appreciated.
Thanks
I am using JeaseCMS 2.8 and the default page already is index.html according to web.xml file.
But this welcome file isn't necessary.