Categories
Java

JSP and dynamic page includes

Coming from the warm sticky confines of ColdFusion development, one gets used to a nifty – and at the time – natural – way of including code dynamically within one’s application. What I am talking about is the ability to tell the server to include a file using a variable name. The server then reads the file, interprets and executes its contents and you separate as friends. In ColdFusion, it looks like this:

<cfinclude url="#var_with_name_of_file_to_include_and_run#">

JSPs have three facitilities to try and do the same thing:
<%@include ... > allows you to include a file statically and have it run. This means that when the JSP is loaded for the first time, and is compiled into a servlet, the include is dropped into the JSP prior to compilation and is compiled into the resulting servlet. If you change the included file, the change will not be reflected. The problem with this otherwise great option is that it cannot get the name of the included file dynamically, as in a variable, as it needs to know the name of the file to include and compile.

Facility number two: <jsp:include ... > does a similar thing: it includes the file into the JSP code but does so every time from scratch, when the page is loaded. If the included file is chagned, the change will be reflected. You can even specify the name of the file dynamically. Problem here is that the included file, even if it is a JSP, will not be executed or parsed and will appear in source form inside the enclosing JSP. This sucks.

The third facility addresses a deficiency that apparently really bothered someone: <jsp:include ... > does not allow you to include files from other contexts, but only files that can be referred to relatively. So when JSTL came into being, its core library’s import tag allows that access to outside-of-context files. But neither can this newer tag offer the dynamic inclusion and execution of files.

The outcome, we found a different path to rendering our pages dynamically, where instead of putting the dynamic content inside the navigation and graphics, we put the navigation into the file we intended to include. Getting there, though, was frustrating and this feels like somewhat of a glaring shortcoming of JSP.

Share
Categories
SQL Server

Updating multiple table rows using a query

So you made a modification to a table and want to update many rows with values from a different table.

If you want to just insert new rows, you do:

INSERT INTO table1
SELECT val1, val2, val3
FROM table2
WHERE some condition

You need to be sure that the columns used in the insert correspond to the rows of the table you insert into.

Still, if you want to update, the syntax is slightly different:

UPDATE table1
SET col1 = t2.col3,
col2 = t2.col4
FROM table1 t1, table2 t2
WHERE t1.t1_id = t2.t1_id

Now I know…

Share
Categories
Java Web Development

MyEclipse Headache – Removing WebProject Capabilities

After braving the upgrade to Eclipse 3.0 and installing MyEclipse we felt like we enjoyed using it and that it was benficial, especially its very very very cool ability to edit and text-complete JavaScript and HTML.
Still, we are unable to make it work properly with JSTL tags, which it could in previous releases.

So I went ahead and clicked on ‘Add WebProject Capabilities’ to the project from the MyEclipse context menu (right-clicking the project folder). This did not help. Worse, it forced me to have a WEB-INF folder no matter what. I would delete it and it would reappear. Grrrreat.

There is no way to remove WebProject Capabilities either. You gotta love one-way settings. After 20 aggravating minutes, the following surgery did the job:

1. Close Eclipse.
2. Edit the .project file and remove any elements that mention of Genuitec (the company builds MyEclipse).
3. Edit the .classpath file and remove WEB-INF from the classpath.
4. Restart Eclipse and right click the project folder
5. In the ‘Java Build Path’ screen, remove WEB-INF from the Output Folder settings and choose a different destination.
6. Delete the WEB-INF folder.

Phew!

Share
Share