<form action="testdissect.jsp" method="POST">
<textarea name="stuff"></textarea>
<input type="submit" value="split"/>
</form>
output:<br/>
<%
if(request.getParameter("stuff")!=null) {
String stuff = (java.lang.String) request.getParameter("stuff");
stuff = stuff.replaceAll("\\n|\\r",""); // (optional) remove line breaks
String[] chunks = stuff.split(";");
for(int i=0; i < chunks.length; i++)
out.println("["+i+"] "+chunks[i]);
}
%>
Showing posts with label JSP. Show all posts
Showing posts with label JSP. Show all posts
Thursday, September 04, 2008
How to Split a String Based on a Delimeter using Java
Sunday, December 11, 2005
Passing Values Out from a JSP 2.0 .tag file
This is really poorly documented on the web, so here goes:
There seem to be two ways to get data OUT of a tag.
Method #1:
Use the request scope. Inside the .tag file, try this:
If you need to vary the name of the request Attribute, pass it in to the .tag file in an attribute then use jspContext.getAttribute(nameOfYourTagAttributeHere) to grab it into a String.
Anyhow, now you can access it in the calling JSP using EL.
Method #2:
I've only read about this one, haven't tried it, but here goes:
There seem to be two ways to get data OUT of a tag.
Method #1:
Use the request scope. Inside the .tag file, try this:
<%
String led = "zeppelin";
request.setAttribute("led", led);
%>
If you need to vary the name of the request Attribute, pass it in to the .tag file in an attribute then use jspContext.getAttribute(nameOfYourTagAttributeHere) to grab it into a String.
Anyhow, now you can access it in the calling JSP using EL.
<c:out value="${led}"/>
Method #2:
I've only read about this one, haven't tried it, but here goes:
A tag receives input through its attributes. In addition to the output text produced by the tag file, a tag can also "output" data by creating EL variables. A tag file might return a value to the page that called it as follows:
<%@ variable name-given="filesincluded" scope="AT_END" %>
The "name-given" provides the name of the variable to set in the page after the tag has completed. "AT_END" specifies that the variable is set when the tag file completes.
How to Pass a HashMap or Other Type into a JSP 2.0 tag file
First, lets assume your HashMap has the name "myHashMap"
Your call to the tag file could look like this:
For me, the EL kept trying to change the hashmap to a string inside the .tag file. So I had to do the following at the top of the .tag file:
Then I could use the map as usual:
Your call to the tag file could look like this:
<mytaglibrary:mytag map="${myHashMap}">
For me, the EL kept trying to change the hashmap to a string inside the .tag file. So I had to do the following at the top of the .tag file:
<%@ tag import="java.util.HashMap"%>
<%@ attribute name="map" required="true" type="java.util.HashMap"%>
Then I could use the map as usual:
The value of map.keyName is ${map.keyName}
Subscribe to:
Posts (Atom)
Labels
- Java (34)
- Oracle (27)
- javascript (24)
- NIX administration (19)
- Reporting (18)
- XML (17)
- Web Graphics (10)
- perl (10)
- CSS (9)
- Tomcat (8)
- Android (7)
- Matlab (7)
- XSL (7)
- HTML (6)
- SQL (6)
- XForms (6)
- browser quirks (6)
- Orbeon XForms (5)
- Solaris (5)
- AJAX (4)
- Mirth Project (4)
- PHP (4)
- Video (4)
- Arduino (3)
- Eclipse (3)
- JPA (3)
- JSP (3)
- JSTL (3)
- LAMPS (3)
- SSH (3)
- SVN (3)
- Hibernate (2)
- Netbeans (2)
- Networking (2)
- Python (2)
- Windows (2)
- Wordpress (2)
- XHTML (2)
- Alfresco (1)
- Architecture (1)
- ArduPilot (1)
- Arduino Yun (1)
- Arduplane (1)
- Audio Recording (1)
- Betaflight (1)
- CouchDB (1)
- DIY (1)
- Design (1)
- FPV (1)
- JSON (1)
- JUnit (1)
- Mobile Development (1)
- Printing (1)
- RC Airplane (1)
- REST (1)
- Scalability (1)
- Struts (1)
- Tools (1)
- Virtualization (1)
- Web services (1)
- camera (1)
- canon (1)
- gphoto2 (1)
- jQuery (1)
- ubuntu (1)
- unix (1)