JSF and j_security_check connection - java

I have an .xhtml page in which I have tried both BalusC's suggestion here and also the following without avoiding the OP's issue
<meta http-equiv="refresh" content="#{session.maxInactiveInterval}"/>
Basically, I start the application and the form based authentication page is rendered. I then wait for the session time to expire. If I try to login after that then the OP's problem occurs.

<meta http-equiv="refresh" content="#{session.maxInactiveInterval}"/>
The #{session} is available in Facelets only. That it doesn't work suggests that you are not using Facelets for this particular view, but its legacy predecesor JSP or even plain vanilla HTML.
For JSP you should be using ${pageContext.session} to get the session, exactly as demonstrated in my answer on the question which you found yourself.
<meta http-equiv="refresh" content="${pageContext.session.maxInactiveInterval}"/>
Or, much better, get rid of legacy JSP altogether and replace it by its successor Facelets.

Related

Jsp page takes too much time in edge but works in chrome browser and incognito mode

I am working on a jsp web application, There is a jsp page which has datatable that has too many records , but the page loads quickly in chrome or in incognito mode of edge . But when I tried to load it in the normal edge browser It takes lot of time,
Also there is a extension called Microsoft editor If I disable it then the page loads faster. But this is not the actual solution .
I have tried adding
<meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate">
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="Expires" content="-1">
in the jsp page. Can someone tell me the reason behind this

Spring Boot & Thymeleaf - remove strict HTML error checking

I am using Spring Boot for an MVC application, and my view technology is Thymeleaf. One of the things I need to do is copy the HTML of an existing website (not my doing...) and render it using Thymeleaf. However, some of the website's source HTML contain unclosed HTML tags (such as <meta>, <link>, <input>), or HTML tags with elements not surrounded by quotes, for example:
<div id=1></div>
instead of
<div id="1"></div>
Of course in the browser this works... But Thymeleaf will not allow this and doesn't serve the page. Is there any way to allow more lenient rules for this? I've searched Thymeleaf's documentation and Spring Boot reference and have found no answer.
Just for clarification - I've not even configured my own beans for Thyemeleaf, just added it to the classpath via maven as one of the spring-boot-starters. So right now these are default settings.
I know i am giving answer after long time but still if it can help to anyone it's good to share.
I resolved the problem after setting up one property "spring,thymeleaf.mode" to "LEGACYHTML5".
spring.thymeleaf.mode=LEGACYHTML5
And in the pom.xml, add the dependency:
<dependency>
<groupId>net.sourceforge.nekohtml</groupId>
<artifactId>nekohtml</artifactId>
<version>1.9.21</version>
</dependency>
If you want to disable caching of thymeleaf then thymeleaf caching
spring.thymeleaf.cache=false
Spring Boot 1.5.3 supports Thymeleaf 3. Thymeleaf 3 has full html5 markup support.
Add following lines to your pom.xml to override Thymeleaf version in Spring boot and you'll be able to use unclosed tags.
<properties>
<thymeleaf.version>3.0.6.RELEASE</thymeleaf.version>
<thymeleaf-layout-dialect.version>2.2.1</thymeleaf-layout-dialect.version>
...
</properties>
As #mussdroid said, everything needs to be in valid XML. Here is part of Thymeleaf's documentation explaining the background for this: http://www.thymeleaf.org/doc/articles/fromhtmltohtmlviahtml.html
Also, if this is a problem, I believe you can turn on legacy-mode to allow non-XML templates, though I would prefer using valid XML if possible:
http://www.thymeleaf.org/doc/tutorials/2.1/usingthymeleaf.html#what-kind-of-templates-can-thymeleaf-process
I don't know myself how to change the mode, but I'm sure DuckDuckGo does or someone on this site.
Everything should be xthml format
For example ;
HTML LINK
<link rel="stylesheet" type="text/css" href="mystyle.css">
THYMELEAF LINK SHOULD BE ending with "/> "
<link rel="stylesheet" href="print.css" media="print" type="text/css" />
HTML META
<meta charset="UTF-8">
THYMELEAF META SHOULD BE ending with "/>"
<meta charset="utf-8"/>
Samples
<input type="text" name="lastname" disabled /> wrong
<input type="text" name="lastname" disabled="disabled" /> correct
otherwise pages will not be displayed because of xhmtl rules applied.
Please have a look at the link , avoid this kind of mistakes
HTML and XHTML
On the other hand when the page is return to browser you will see xhtml rules converts to html format again. But the actually page it run on a server before sending client thymeleaf xhtml rules are applied.

JSP file output not updating after changes [Eclipse Internal Web Browser issue]

Let me start off by saying that I'm completely new to JSP and servlets. I'm using Eclipse and Tomcat 7. I tried the answer given on this question: JSP page is not getting refreshed after updating, but it still doesn't update.
Here is my jsp file:
<%# page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Hello world</title>
</head>
<body>
<%="Hello World JSP"%>
</body>
</html>
When I run this, the appropriate "Hello World JSP" is output. However if I change the string and run it again, the same old output is displayed. I have to restart Eclipse in order to have the output change, so I'm assuming eclipse is caching the compiled page. Any ideas?
EDIT: The problem has been narrowed down to the Browser cache. The problem only occurs when I use Eclipse's "Internal Web Browser" (Doesn't matter which browser I link that to in preferences). When I run it externally, (through either IE or Firefox), the changes are made.
I'd still like to know however how I can make it so that it updates even using "Internal Web Browser", since it's more convenient.
Check if the broswer is the one caching your page contents even though Tomcat republishes.
Clear your browser's cache to see if this helps.
Also, you can put your browser in a cache-less mode in their options:
Firefox:
Go to Tools menu -> Options -> Advanced tab -> Network subTab and set the value to 0 in the 'Limit cache to #MB of space' field after checking the 'Ignore automatic cache administration' field.
Chrome:
In the Chrome configuration page, go to the Privacy section and click on the 'Content settings' button. In the appearing dialog change the selected option on the Cookies section to any other option that suits your needs.
Eclipse's Internal Web Browser:
Check this question's accepted answer to see how to do it.
Just DELETE your old SERVER(local server like 'Tomcat'). And then again create NEW SERVER.
Just came across this thread. In order to solve this issue, you may need to open up the source code file relating to your JSP page. Make some miniscule change (for instance, add a space, and then remove it) and SAVE the page. Refresh the webpage that you are running locally. The change should be there.

GWT i18n HTML files

I have already provided GWT's i18n feature for java, UI Binder and trying to provide i18n with pure, none-hosted in java HTML file.
After reading "Declarative Layout with UiBinder" I implement some code, but it didn't work:
<html xmlns:ui="urn:ui:com.google.gwt.uibinder">
<ui:with field='i18n' type='//.exampleConstants'/>
<head>
<title>Title of none-hosted HTML file and i18n part: <ui:text from='{i18n.title}'/></title>
</head>
<body>
...
</body>
</html>
The solution with id's (described on same page: https://developers.google.com/web-toolkit/doc/latest/tutorial/i18n/) which will be pick-upped by RootPanel, smth like:
RootPanel.get("appTitle").add(new Label(constants.stockWatcher()));
Didn't work too, because my HTML file isn't bundled with Java.
How to do i18n in HTML files?
Well, you'd have a Catch-22 here: the HTML file couldn't know which text to use until the JavaScript compiled out of your Java code is loaded, which is done by the page, so after it's loaded.
You have to use standard Java web app techniques to internationalize your HTML page, e.g. make it a JSP, and detect the preferred language out of the Accept-Languages request header. If you do that, then generate the appropriate <meta name="gwt:property" content="locale=XX"> so the GWT app bootstrap (the .nocache.js file) won't have to guess it too, which could result in the GWT app running in a different locale than the one the HTML was generated with.

Java: How to invoke code running on a server from a browser?

Is there somehow that I can invoke Java running on a server from a web browser? I would like:
User navigates to URL in a browser
User fills in input boxes (text)
User presses submit button
Input fields are sent as parameters to java that is executing on the server
A new html page is displayed that was generated by the java running on the server.
What is the standard way to do this, or something similar to this.
I think with PHP this would be relatively simple. I think that you would just pass arguments after the URL like this: www.mysite.com/folder?arguments.
Yes, this is possible (and is extremely common). Two of the most common ways are Java Servlets (where responses are generated purely via Java code) and Java Server Pages (where server logic is intermingled within HTML, similar to ASP or PHP).
There are countless ways to serve HTML from Java but virtually all of them rely on java servlets and java server pages (JSPs) which are Java's specification for handling web requests.
The absolute bare minimum to get going:
Install Java EE SDK ensuring to also install Netbeans and Glassfish.
Launch Netbeans and create a "Java Web" / "Web Application" project
Enter a project name, e.g. MyWebApp
In the Server and Settings screen, you need to Add... your server so do so. Point to the file location of your Glassfish server and enter the admin name and password
Ignore the framework stuff and Finish
NetBeans will generate a sample app and you can click straightaway on Run Main Project. It will deploy your app to Glassfish and load http://localhost:8080/MyWebApp/ from your default browser
Important things to note:
A file called web.xml tells the host server some basics about your web app. This file can contain a lot of other stuff but the default is some boiler plate. The most interesting part says <welcome-file>index.jsp</welcome-file> which means when you load http://localhost:8080/MyWebApp/ it will default to load index.jsp.
The index.jsp is what gets loaded if you don't specify a page to the server. If you look at index.jsp it's just HTML with some JSP markup.
<%#page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<h1>Hello World!</h1>
</body>
</html>
Creating new JSPs is as simple as writing HTML. Netbeans has a wizard to create a simple JSP.
You can embed chunks of Java into a .jsp easily and step in and out of Java / HTML with the <% %> notation such as
<%
for (int i = 0; i < 10; i++) {
%>
Hello <%=i%>
<% } %>
Glassfish is just one possible app server. As long as you write compliant code it should functional with only minimal or zero modifications on any other implementation of Java Servlet / JSP spec. e.g. Jetty, Tomcat, oc4j, JBoss, WebSphere etc.
This is just the tip of the iceberg. You can make things as simple or complex as you like.
Once you know the basics then it's up to you how deep you go. More advanced topics would be:
Taglibraries - these can remove a lot of java clutter and are considered more correct
Expressions - using expressions inside JSP pages to reduce the need for messy <%= notation
Custom servlets let you move model / business stuff into a Java class and leave the .jsp to just presentational
MVC web frameworks like Struts, Spring etc.
Security & filtering
It's a massive subject but it's fairly easy to do something quick and dirty.
As a followup to Mark Peters answer, you need a java web server like Tomcat or GlassFish in order to use servlets or jsps. There are a lot of great frameworks for Java that help you abstract away from the original servlet classes, but I'll let you look those up and decided if you even need them for something this simple.
If you want to pass arguments in a URL, then easier approach is Axis
You can display result with javascript on your page.
If you want to pass arguments in a URL, then easier approach is Axis
My school has an apache server that we are required to use. I was not allowed to install tomcat. I ended up invoking my server side Java using PHP. Not the most beautiful solution but it works.

Categories

Resources