In my JSP I have
<%# page import "com.example.Elenco" %>
but inside a very small scriptlet, whenever i try to instantiate Elenco, it requires the full name.
If i write
Elenco a = new Elenco(blabla);
Eclipse gives the following error: "Elenco cannot be resolved to a type", and I have to write
com.example.Elenco a = new com.example.Elenco(blabla);
that is pretty uncomfortable. Do exist any method to make the package name not mandatory?
Your import directive seems to be wrong. Try
<%# page import="com.example.Elenco" %>
You are missing the =.
The syntax is
<%# page import="com.example.Elenco" %>
^--- you need an equal sign here
Related
I have an EJS file called 'test.ejs', which contains:
<p>This is a test statement</p>
Then, I have another file called 'index.ejs' which is in the same folder as the other EJS file. Index.ejs contains:
<%- include ("test") %>
<p>Hello world</p>
However, when I load the page, I do not get any output. Instead, the page just loads endlessly.
My routes in Express are being handled properly and my controllers are working too. All this is tested.
Also, can someone refer me to good EJS documentation?
Try this:
<% include ./test %>
<p>Hello world</p>
try: <% include /pathname/test %>
Documentation is sparse but the official one works
http://www.embeddedjs.com/
or
http://ejs.co/
I have a jsp page which takes up first name and last name in chinese language. I am using the struts framework.
I need to pass the first name and last name from the JSP to servlet in terms of unicode characters.
I am doing the following changes:
JSP Changes:
1) <%# page pageEncoding="UTF-8" contentType="text/html; charset=UTF-8" %>
2) meta content="content-type" content="text/html; charset=utf-8" in the header,
The filter which is called before the action servlet, I have used the following code:
request.setCharacterEncoding("UTF-8");
response.setContentType("UTF-8");
This did not work, the unicode characters which are passed are incorrect, or something not readable.
Considering the MVC framework already creates the request object by the time it reaches the filter,
I modified the JSP to include the following lines of code
<%# taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
< fmt:requestEncoding value="UTF-8" />
< fmt:setLocale value="zh_CN"/>
None of the above changes have worked. Please help me to get the correct unicode characters in the action class.
IS there any modification i need to make in the config files.
You also need to set the Bundle basename.
<fmt:setBundle basename = "[base_file_name_of_language_file]"/>
where [base_file_name_of_language_file] is equal to whatever name you set your language properties file name to be.
For example, the "MyLanguageFileName" in this file name :
MyLanguageFileName_zh_CN.properties
I am trying to use custom tag with variables.
for eg)
<c:forEach var="test" items="itemstest">
${test}
</c:forEach>
In the above code i am able to access the test value inside the <c:forEach> tag.
I need to create a custom tag with similar functionality.
I have got info from the oracle docs http://docs.oracle.com/javaee/5/tutorial/doc/bnamu.html under title Declaring Tag Variables for Tag Handlers.
Can anyone pls help me to implement the same with example.
Hi i have solved it in the following way
class: test.java
public void doTag() throws JspException, IOException {
getJspContext().getOut().flush();
//any method or operation
super.doTag();
getJspContext().setAttribute(variable, "Hello");
}
Create getter setter for variable
tld file:
<tag>
<name>test</name>
<tag-class>com.org.test</tag-class>
<body-content>empty</body-content>
<attribute>
<name>inputValue</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>variable</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
</tag>
jsp file:
<%# taglib uri="/WEB-INF/tld/tldfilename.tld" prefix="tag" %>
<tag:test inputValue="hello" variable="testValue"/>
${testValue}
For something so simple, you may be better off using tag files, which makes it easy to create a tag library using some small additions to the normal jsp syntax (and is part of the standard)
http://docs.oracle.com/javaee/1.4/tutorial/doc/JSPTags5.html
A "tag with variables" is done using an attribute declaration, JSP code is quite simple:
<%#tag pageEncoding="utf-8" %>
<%-- dont forget to add declaration for JSTL here -->
<%#attribute name="test" type="java.lang.String" required="true" %>
<c:forEach var="test" items="itemstest">
${test}
</c:forEach>
See the linked documentation on whre to put and name the files to make them accessible within you own jsp files.
As the title suggests I am trying to resolve a localisation string inside a repeater. I have a wysiwyg editor to input some html on the form tab of the document type, so the source would look like this
Field1: "{$localstring$}"
Then in the transformation I have
<li><%# Eval("Field1") %></li>
This outputs the string as
{$localstring$}
and doesn't resolve this as a macro and go lookup the localstring in the UI culture localisation.
I have tried different things including
<%# Eval(CMS.GlobalHelper.ResHelper.LocalizeString("Field1")) %>
and
<%# Eval(CMS.CMSHelper.CMSContext.CurrentResolver.ResolveMacros("Field1")) %>
all of which give the same output, can anyone point me in the right direction? I am sure it's the way Eval is being called.
Thanks in advance.
in case somebody else searches for this: if you want to use localization string custom.my-string in ASPX transformation, you should resolve it as follows:
<%# CMS.CMSHelper.CMSContext.CurrentResolver.ResolveMacros("{$custom.my-string$}") %>
note: no spaces! if you add spaces like this: "{$ custom.my-string $}" - it WILL NOT work.
The correct syntax is following:
<%# CMS.CMSHelper.CMSContext.CurrentResolver.ResolveMacros(Eval("Field1").ToString()) %>
I created a Display Template which when passed a string renders a disabled text box
<%# Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<String>" %>
<%: Html.TextBoxFor(model => model, new { disabled = "disabled" })%>
Which works great. However, for some reason MVC wants to try and stuff DateTimes and Ints through it as well, which is throwing exceptions
The model item passed into the dictionary is of type 'System.Int32', but this dictionary requires a model item of type 'System.String'.
Any ideas?
You don't need to strongly type the template to a String.
you can try something like this :
<%# Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl" %>
<%= Html.TextBox("", ViewData.TemplateInfo.FormattedModelValue,
, new { disabled = "disabled" }) %>
And in your view you call it like this
Html.DisplayModelFor(model => mode.name);
For more information see an example of the default built-in editor template for the string in Brad Wilson article in his his series on Templates in ASP.NET MVC.
You should consider going through the complete series. I can't express how helpful this series was for me.