Showing posts with label jsp. Show all posts
Showing posts with label jsp. Show all posts

Thursday, July 3, 2014

How to set the row id [ TR ] and column id [ TD] in displaytag?

First, I do not believe it is possible to set the ids on the td's or tr's in displaytag without modifying the source. This has not left my list of things to do, but for now I have a work around for you.
Instead of defining your table:
 id='row' name="..." export="true" requestURI="">
   property="usefulData" title="Useful data" sortable="true" />
  ... more columns ...
do this:
 id='row' name="..." export="true" requestURI="">
   title="Useful data" sortable="true" >
     id='${row.usefulData}' class='css_class_selector'>${row.usefulData}
  
Note the span wrapping the printed data. Now you can select the data relating printing inside your table, which is probably what you want; to select your data, as opposed to specifically selecting the td's and tr's.

Tuesday, June 17, 2014

Accessing a value in Struts ActionForm from JSP

Try
<h1>Hello  <bean:write name="RegistrationForm" property="userid" />!</h1>
it doesn't matter what the internal name / coding of your formbean is. All what matters is how the getters and setters are named. Your getter is named getUserid() to the javabean property is userid.

Thursday, May 22, 2014

How to evaluate a scriptlet variable in EL?

So you want to evaluate a scriptlet variable in EL? Store it as a request attribute.
<%
    String var = "some";
    request.setAttribute("var", var);
%>

<c:if test="${param.variable1 == 'Add' && var == 'some'}">
However, this makes no sense. You should avoid scriptlets altogether and use JSTL/EL to prepare this variable. So if you make the functional requirement more clear, e.g. "How do I do this (insert scriptlet code snippet) using JSTL/EL?", then we'll be able to suggest the right approach.

See also:

difference between page and request

hi,
Page Scope is the smallest scope, and is a representation of the PageContext object for your JSP. Each JSP has it's own page scope, so objects in the page scope of one JSP are not accessible to other JSPs. This is sorta like making a private variable in Java.

Request scope is the next smallest scope, and is represented with the JSP's request object. All JSPs and servlets that share a request share the request scope. For example, if I have a JSP that forwards to another page, and that second page includes a third JSP page, then all three pages are in the same request, and can share objects through the request scope. A special note here, is the response.redirect(), will create a new request, unlike forwards and includes. Also note, a new request is made every time the user gets a new page, be it by clicking a link, a button, or some JavaScript call.

http://www.coderanch.com/t/291025/JSP/java/difference-page-request

Tuesday, May 13, 2014

The ternary operator and JSP

This interesting bit of JSTL for JSP is worth writing about.
Background: The ternary operator allows you to combine an if-then-else statement into one line using a bunch of symbols. It makes code a bit harder to read, but it also makes it look cool.
I can turn this:


  not empty


  empty

into this:
It even parses variables for output:
And you don’t even need the c:out:
${not empty somevariable ?  somevariable: 'empty'}
Old hat yes, but I thought an interesting tidbit to write about!

Evaluate empty or null JSTL c tags

You can use the  or  for this.
 test="${empty var1}">
    var1 is empty or null.

 test="${not empty var1}">
    var1 is NOT empty or null.
or

     test="${empty var1}">
        var1 is empty or null.
    
    
        var1 is NOT empty or null.
    
The ${not empty var1} can also be done by ${!empty var1}.
To learn more about those ${} things (the Expression Language, which is a separate subject from JSTL),check here.

Thursday, August 22, 2013

Difference between JSP include directive and JSP include action

  • <%@ include file=”filename” %>   is the JSP include directive.
    At JSP page translation time, the content of the file given in the include directive is ‘pasted’ as it is, in the place where the JSP include directive is used. Then the source JSP page is converted into a java servlet class. The included file can be a static resource or a JSP page. Generally JSP include directive is used to include header banners and footers.The JSP compilation procedure is that, the source JSP page gets compiled only if that page has changed. If there is a change in the included JSP file, the source JSP file will not be compiled and therefore the modification will not get reflected in the output.
  • is the JSP include action element.
    The jsp:include action element is like a function call. At runtime, the included file will be ‘executed’ and the result content will be included with the soure JSP page. When the included JSP page is called, both the request and response objects are passed as parameters.If there is a need to pass additional parameters, then jsp:param element can be used. If the resource is static, its content is inserted into the calling JSP file, since there is no processing needed.

Tuesday, February 5, 2013

JSP Variable Accessing in JavaScript


alert("${variable}");
or
alert("<%=var%>");
or full example
<html> 
<head>
<script language="javascript"> 
function access(){ 
<% String str="Hello World"; %>
var s="<%=str%>"; 
alert(s); 
} 
</script> 
</head> 
<body onload="access()"> 
</body> 
</html>

Tuesday, August 7, 2012

Caching jsp pages on jboss

I found no relief from clearing out the browser cache or setting IE up to get new versions of pages everytime......BUT....................

If you delete the contents under the "work" folder of the JBoss alias your running, all these JSP problems go away. I only see the current JSP pages that are actually deployed under the alias I'm running. No more old JSP data. That was really weird to me and was driving me nutts.

I deleted everything under C:\jboss-4.0.2\server\default\work

since I'm running the "default" alias.

https://community.jboss.org/thread/38118

Wednesday, June 6, 2012

Difference between JSP include directive and JSP include action

  • <%@ include file=”filename” %> is the JSP include directive.
    At JSP page translation time, the content of the file given in the include directive is ‘pasted’ as it is, in the place where the JSP include directive is used. Then the source JSP page is converted into a java servlet class. The included file can be a static resource or a JSP page. Generally JSP include directive is used to include header banners and footers. The JSP compilation procedure is that, the source JSP page gets compiled only if that page has changed. If there is a change in the included JSP file, the source JSP file will not be compiled and therefore the modification will not get reflected in the output.
  • is the JSP include action element.
    The jsp:include action element is like a function call. At runtime, the included file will be ‘executed’ and the result content will be included with the soure JSP page. When the included JSP page is called, both the request and response objects are passed as parameters. If there is a need to pass additional parameters, then jsp:param element can be used. If the resource is static, its content is inserted into the calling JSP file, since there is no processing needed.
http://javapapers.com/jsp/difference-between-jsp-include-directive-and-jsp-include-action/

difference between jsp forward and redirect

  • redirect sets the response status to 302, and the new url in a Location header, and sends the response to the browser. Then the browser, according to the http specification, makes another request to the new url
  • forward happens entirely on the server. The servlet container just forwards the same request to the target url, without the browser knowing about that. Hence you can use the same request attributes and the same request parameters when handling the new url. And the browser won't know the url has changed (because it has happened entirely on the server)
     
http://stackoverflow.com/questions/6068891/difference-between-jsp-forward-and-redirect

Thursday, January 12, 2012

What is the difference between JSF, Servlet and JSP?

JSP (JavaServer Pages)

JSP is a Java view technology running on the server machine which allows you to write template text in (the client side languages like HTML, CSS, JavaScript and so on). JSP supports the so-called taglibs which are backed by pieces of Java code with which you can control the page flow and/or output dynamically (programmatically). A well known taglib is JSTL. JSP also supports Expression Language which can be used to access backend data (actually, the attributes which are available in page, request, session and application scopes), mostly in combination with taglibs.
When a JSP is requested for the first time or when the webapp starts up, the servlet container will compile it into a class extending HttpServlet and use it during the webapp's lifetime. You can find the generated source code in the server's work directory. In for example Tomcat, it's the /work directory. On a JSP request, the servletcontainer will execute the compiled JSP class and send the generated output (usually just HTML/CSS/JS) through the webserver over network to the client side which in turn displays it in the webbrowser.

Servlets

Servlet is an Java application programming interface (API) running on the server machine which can intercept on the requests made by the client and can generate/send a response accordingly. A well known example is the HttpServlet which provides methods to hook on HTTP requests using the popular HTTP methods such as GET and POST. You can configure HttpServlets to listen on a certain HTTP URL pattern, which is configureable in web.xml, or more recently with Java EE 6, with @WebServlet annotation.
When a Servlet is requested for the first time or when the webapp starts up, the servlet container will create an instance of it and keep it in memory during webapp's lifetime. The same instance will be reused for every incoming request whose URL matches the servlet's URL pattern. You can access the request data by HttpServletRequest and handle the response by HttpServletResponse. Both objects are available as method arguments inside any of the overridden methods of HttpServlet, such as doGet() and doPost().

JSF (JavaServer Faces)

JSF is a component based MVC framework which is built on top of the Servlet API and provides components in flavor of taglibs which can be used in JSP or any other Java based view technology such as Facelets. Facelets is much more suited to JSF than JSP. It namely provides great templating capabilities such as composite components, while JSP basically only offers the for templating, so that you're forced to create custom components with raw Java code (which is a bit opaque and a lot of tedious work in JSF) when you want to replace a repeated group of components by a single component. If you can, I recommend to drop JSP and go for Facelets when you want to develop with JSF.
As being a MVC (Model-View-Controller) framework, JSF provides the FacesServlet as the sole request-response Controller. It takes all the standard and tedious HTTP request/response work from your hands, such as gathering user input, validating/converting them, putting them in model objects, invoking actions and rendering the response. This way you end up with basically a JSP or Facelets (XHTML) page for View and a Javabean class as Model. The JSF components are been used to bind the view with the model (such as your ASP.NET web control does) and the FacesServlet uses the JSF component tree to do all the work.

http://stackoverflow.com/questions/2095397/what-is-the-difference-between-jsf-servlet-and-jsp