프로그램/struts 1.x

struts tag example

mulderu 2008. 8. 25. 12:56
제어1)
<%@ page language="java" %> 
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<html:html>
<head>
<title>
<bean:message key="welcome.title"/>
</title>
<html:base/>
</head>
<body>

<!-- This will set the number to be guessed -->
<bean:define id="theNumber" value="7"/>

<html:errors/>
<html:form action="/setName">
<html:hidden property="action"/>
<bean:message key="prompt.name"/>
<html:text property="name" size="16" maxlength="16"/>
<br></br>
<html:submit>
<bean:message key="button.save"/>
</html:submit>
<html:reset>
<bean:message key="button.reset"/>
</html:reset>
</html:form>
<hr></hr>
<logic:present name="name">

<bean:write name="name" property="name"/>
<br></br>

<!-- Equal To -->
<logic:equal name="name" property="name" value="<%= theNumber %>" >
<bean:message key="result.correct"/>
</logic:equal>

<logic:notEqual name="name" property="name" value="<%= theNumber %>">
<!-- Less Than -->
<logic:lessThan name="name" property="name" value="<%= theNumber %>" >
<bean:message key="result.lessThan"/>
</logic:lessThan>
<!-- Greater Than -->
<logic:greaterThan name="name" property="name" value="<%= theNumber %>" >
<bean:message key="result.greaterThan"/>
</logic:greaterThan>
</logic:notEqual>
<hr></hr>
</logic:present>
</body>
</html:html>


-------------------------------------------------------------


package com.masslight.actions;

import java.util.Vector;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.util.Locale;
import java.util.Hashtable;
import javax.servlet.*;
import javax.servlet.http.*;
import org.apache.struts.action.*;
import org.apache.struts.util.*;

public final class SetListAction extends Action {

// The constructor method for this class
public SetListAction() {
}

// This sets the list as a session bean
public ActionForward perform(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException {

HttpSession session = request.getSession();

java.util.ArrayList list = new java.util.ArrayList();
list.add("ONE");
list.add("TWO");
list.add("THREE");

session.setAttribute("list",list);

return (mapping.findForward("success"));
}
}


<%@ page language="java" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>

<html>
<head>
<title>
Headers with Struts
</title>
</head>
<body>
<logic:present header="User-Agent">
<bean:header id="theheader" name="User-Agent"/>
You are currently running <bean:write name="theheader"/>
</logic:present>
</body>
</html>


-------------------------------------------------------------

cookie access :


<%@ page language="java" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<html:html>
<head>
<title>
<bean:message key="welcome.title"/>
</title>
<html:base/>
</head>
<body>

<!-- This will set the number to be guessed -->
<bean:define id="theNumber" value="7"/>

<html:errors/>
<html:form action="/setName">
<html:hidden property="action"/>
<bean:message key="prompt.name"/>
<html:text property="name" size="16" maxlength="16"/>
<br>
<html:submit>
<bean:message key="button.save"/>
</html:submit>
<html:reset>
<bean:message key="button.reset"/>
</html:reset>
</html:form>
<hr>
<logic:present cookie="name">

<bean:cookie id="namecookie" name="name"/>
<bean:write name="namecookie" property="name"/>
<bean:write name="namecookie" property="value"/>
<br>

<!-- Equal To -->
<logic:equal name="namecookie" property="value" value="<%= theNumber %>" >
<bean:message key="result.correct"/>
</logic:equal>

<logic:notEqual name="namecookie" property="value" value="<%= theNumber %>">
<!-- Less Than -->
<logic:lessThan name="namecookie" property="value" value="<%= theNumber %>" >
<bean:message key="result.lessThan"/>
</logic:lessThan>
<!-- Greater Than -->
<logic:greaterThan name="namecookie" property="value" value="<%= theNumber %>" >
<bean:message key="result.greaterThan"/>
</logic:greaterThan>
</logic:notEqual>
<hr>
</logic:present>
</body>

</html:html>

-------------------------------------------------------------
-- select box and more

<%@ page language="java" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-form.tld" prefix="form" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>

<html:html locale="true">
<head>
<title>
Modify employee
</title>
<html:base/>
</head>
<body bgcolor="white">
<h3>
Modify employee
</h3>
<html:errors/>
<hr/>
<html:form action="/employeemodify">
<html:hidden name="employee" property="employeeid"/>
<table>
<tr>
<td>
First Name
</td>
<td>
<html:text name="employee" property="firstname" size="20" maxlength="20"/>
</td>
</tr>
<tr>
<td>
Last Name
</td>
<td>
<html:text name="employee" property="lastname" size="20" maxlength="20"/>
</td>
</tr>
<tr>
<td>
Extension
</td>
<td>
<html:text name="employee" property="extension" size="4" maxlength="4"/>
</td>
</tr>
<tr>
<td>
City
</td>
<td>
<html:select name="employee" property="cityid">
<html:options collection="cities"
name="employee" property="cityid" labelProperty="name"/>
</html:select>
</td>
</tr>
<tr>
<td>
Department
</td>
<td>
<html:select name="employee" property="departmentid">
<html:options collection="departments"
name="employee" property="departmentid" labelProperty="name"/>
</html:select>
</td>
</tr>
</table>
<html:submit>
Modify
</html:submit>
<html:reset>
Reset
</html:reset>
</html:form>
<hr/>
<html:link href="index.jsp">
Return to My Co - Main Menu
</html:link>
</body>
</html:html>



-------------------------------------------------------------
-- select box and more