Struts.xml설정
<constant name="struts.ui.theme" value="defaultThem" />
1.Eclipse경우 src/template.defaultThem/ 을 만든다. 2.theme.properties 파일을 만들어 parent = simple 를 기입한다. 3. 고치고 싶은 xx.ftl를 수정후 저정한다. ex) text.ftl
<#include "/${parameters.templateDir}/simple/controlheader.ftl" />
<#include "/${parameters.templateDir}/simple/text.ftl" />
<#include "/${parameters.templateDir}/${parameters.theme}/controlfooter.ftl" />
select.ftl
<#include "/${parameters.templateDir}/simple/controlheader.ftl" />
<#include "/${parameters.templateDir}/simple/select.ftl" />
<#include "/${parameters.templateDir}/${parameters.theme}/controlfooter.ftl" />
controlfooter.ftl
${parameters.after?if_exists}<#t/>
 <#lt/>
    <#include "/${parameters.templateDir}/defaultTheme/controlfooter-core.ftl" />
controlfooter-core.ftl
<#if parameters.required?default(false) && parameters.requiredposition?default("right") == 'right'>
*

4. xxx.jsp태그에 "required="true"를 기입

이렇게 설정하고 jsp를 보면 *가 옆에 붙어있다.

'Struts2' 카테고리의 다른 글

다중전송방지  (0) 2010.10.14
<s:select>태그 사용  (0) 2010.08.27
Struts2에서 예외처리  (0) 2010.08.26
struts.properties , 사용방법  (0) 2010.08.16
현재 URL 가져오기  (0) 2010.08.14
struts.xml
            <interceptor-stack name="interceptStack">
                <interceptor-ref name="sessionLock" />
                <interceptor-ref name="exception" />
                <interceptor-ref name="loginChk" />
                <!-- interceptor-ref name="cmAuth" /-->
                <interceptor-ref name="parentPage" />
                <interceptor-ref name="tokenSession">
                  <param name="includeMethods">
                    delete,delUser,confirm,back,update,add
                  </param>
                </interceptor-ref>                
                <interceptor-ref name="defaultStack" />
            </interceptor-stack>
xxx.jsp



폼태그하나에 한개의 토큰이 존재. submit버튼 형식이 아닌 a태그를 사용하는경우


 
   " border="0" />

'Struts2' 카테고리의 다른 글

필수항목에 *를 붙이기  (0) 2010.10.14
<s:select>태그 사용  (0) 2010.08.27
Struts2에서 예외처리  (0) 2010.08.26
struts.properties , 사용방법  (0) 2010.08.16
현재 URL 가져오기  (0) 2010.08.14
--java
private List<Map<String, String>> parentList = new ArrayList<Map<String, String>>();


HashMap<String, String> map;
for (int i = 0; i < objectList.size(); i++) {
        JSONObject categoryInfo = objectList.getJSONObject(i);
        map = new HashMap<String, String>();
        map.put("id", categoryInfo.getString("categoryId"));
        map.put("name", categoryInfo.getString("categoryName"));
        categoryMapList.add(map);
}

--jsp
<s:select name="parentId" id="parentId" list="parentList"  cssClass="DropDownList" listKey="%{id}" listValue="%{name}"
 headerKey="" headerValue="%{getText('common.dropdown.select')}" value="%{parentId}" required="true" />

'Struts2' 카테고리의 다른 글

필수항목에 *를 붙이기  (0) 2010.10.14
다중전송방지  (0) 2010.10.14
Struts2에서 예외처리  (0) 2010.08.26
struts.properties , 사용방법  (0) 2010.08.16
현재 URL 가져오기  (0) 2010.08.14
인터셉터에서 에러처리를 전부 담당해서 할수 있도록 인터셉터 클래스를 만들어 놓은곳
하지만 생각외로 잘안되더라는 다만, 인터셉터에서 발생한 에러는 제대로 Catch에서 로그를 남기더라는.




'Struts2' 카테고리의 다른 글

다중전송방지  (0) 2010.10.14
<s:select>태그 사용  (0) 2010.08.27
struts.properties , 사용방법  (0) 2010.08.16
현재 URL 가져오기  (0) 2010.08.14
Struts2 @Results 에서 params이용 방법  (0) 2010.08.12
struts.properties
제한 없이 무한업로드 가능
struts.multipart.maxSize=-1


인터셉터에서 용량제한 
 <interceptor-ref name="fileUpload">
     <param name="maximumSize">10240</param>
 </interceptor-ref>

ex) properties가 2메가 인터셉터가 1메가인 상황에서 2메가를 넘는 에러가 발생할경우. 인터셉터 에러 메세지로 제어 안되는 상황이 발생한다는..

#업로드된 파일 객체가 NULL인 경우
struts.messages.error.uploading=Error uploading_EN: {0}
#최대 크기가 넘어가는 경우
struts.messages.error.file.too.large=File too large_EN: {0} "{1}" {2}
#ContentType이 허가되지 않은 것인 경우
struts.messages.error.content.type.not.allowed=Content-Type not allowed_EN: {0} "{1}" {2}

용량제어 방법은 크게 3가지 방법이 있다.
-struts.xml
-struts.properties
-interceptor



'Struts2' 카테고리의 다른 글

<s:select>태그 사용  (0) 2010.08.27
Struts2에서 예외처리  (0) 2010.08.26
현재 URL 가져오기  (0) 2010.08.14
Struts2 @Results 에서 params이용 방법  (0) 2010.08.12
Validator 날짜 체크 Action  (0) 2010.08.11

방법은... 컨트롤러 역할을 하는 부분에서 뷰단으로 넘어가기 전에 들어온 요청 URL을 request의 attribute로 저장해서 a.jsp에서 뽑아 쓰시거나.. 

request.getAttribute( "javax.servlet.forward.request_uri" ); 
request.getAttribute( "javax.servlet.include.request_uri" ); 

를 사용하시면 됩니다... 

해당 프레임웍에서 최종적으로 뷰 페이지를 호출하는 방식에 따라서 쓰시면 되구요.. 
아마도 forward겠죠..


예를 들어 카트화면이 프레임이나 다른Tiles에 있을경우 리다이렉트가 아니면 화면 변화가 
바로 보이지않는 경우가 있다. 
그리고 이경우 카트에서 선택한 상품을 삭제하더라도 화면상태는 그대로 유지 할경우가 있는데
이경우 인터셉터에서 해당 페이지 주소와 쿼리를 세션에 저정한후 처리 한다. 
방법은 밑과 같이~~

       // action실행
	String result = invocation.invoke();

       // get으로 Request되어 Tiles화면에 표시되는경우 Redirect용 Url를 세션에 보존한다.
        HttpServletRequest request = ServletActionContext.getRequest();
        if ("GET".equals(request.getMethod())) {
        	if (invocation.getResult() instanceof org.apache.struts2.views.tiles.TilesResult) {
        		String redirectUrl = request.getServletPath();
	        	String queryString = request.getQueryString();
	        	if (queryString != null) {
	        		redirectUrl = redirectUrl + "?" + queryString;
	        	}
	        	sessionMap.put(세션보존..);
        	}
		}

	return result;

'Struts2' 카테고리의 다른 글

Struts2에서 예외처리  (0) 2010.08.26
struts.properties , 사용방법  (0) 2010.08.16
Struts2 @Results 에서 params이용 방법  (0) 2010.08.12
Validator 날짜 체크 Action  (0) 2010.08.11
validate money check struts2  (0) 2010.08.10

http://localhost:8080/NecstMarketPlace/product-descriptions-detail.action?serviceId=S0000000002
@Results({
	@Result(name="reload",   type="redirect", location="index.action"),
	@Result(name="productDetail",   type="redirect", params ={"serviceId","${serviceOptionId}"} , location="product-descriptions-detail.action"),
	@Result(name="product",   type="redirect", params ={"categoryId","${categoryId}"},location="product-descriptions.action"),
	@Result(name="success",  type="tiles", location="shoppingcart-purchase.page"),
	@Result(name="input",    type="tiles", location="shoppingcart-purchase.page"),
	@Result(name="review",   type="tiles", location="shoppingcart-purchase.page"),
	@Result(name="complete", type="redirect", location="shoppingcart-purchase!showComplete.action"),
	@Result(name="showcomplete", type="tiles", location="shoppingcart-purchase-complete.page"),
	@Result(name="print",                  location="/WEB-INF/pages/shoppingcart-purchase-print.jsp"),
	@Result(name="download", type="stream",
			params = {
				"inputName", "inputStream",
				"contentType", "${mediaType}",
				"bufferSize", "1024"
			}
		)
})



JSP에서 Param으로 받을경우
"${serviceOptionId}"는 클래스안에서 get/set선언...
클래스 내부에서 사용할경우
get/set으로 선언할 필요까지는 없다.

'Struts2' 카테고리의 다른 글

struts.properties , 사용방법  (0) 2010.08.16
현재 URL 가져오기  (0) 2010.08.14
Validator 날짜 체크 Action  (0) 2010.08.11
validate money check struts2  (0) 2010.08.10
Struts2 exceptionStack logfile  (0) 2010.08.06
 
  /**
     * 
     * Method name:checkDate
     * 
     * description: データFormatをチェック、必須チェック含む
     * 
     * @param strDate チェックしたい項目名
     * @param filedName エラーが発生し、表示する項目名(getText("項目名"))
     * @param action this
     * 
     * Created at:2010/08/11
     *
     */
    public void checkDate(String strDate , String filedName ,BaseAction action){
        // 日付の入力チェックがXMLでは難しいため、javaでチェックする
        // ここで追加したエラーメッセージはJSPので表示される
        String dateName = getText(filedName);
        if (strDate==null || strDate.isEmpty()) {
            // 必須入力チェック
            action.addActionError(getText("errors.required", new String[]{ dateName }));
        }else {
            // 日付フォーマットチェック
            SimpleDateFormat formater = new SimpleDateFormat(getText("java.date.format"));
            formater.setLenient(false); //日付を厳密にチェックするように設定
            Date parsed = null;
            try {
                parsed = formater.parse(strDate);
            } catch(Exception e) {
            }
            if (parsed == null) {
                action.addActionError(getText("errors.invalid.date.format", new String[]{ dateName }));
            }
        }
    }

'Struts2' 카테고리의 다른 글

현재 URL 가져오기  (0) 2010.08.14
Struts2 @Results 에서 params이용 방법  (0) 2010.08.12
validate money check struts2  (0) 2010.08.10
Struts2 exceptionStack logfile  (0) 2010.08.06
Struts2 validation Byte Check  (0) 2010.08.06

        </field-validator>
        <field-validator type="regex">
          <param name="expression">
            ^(\$|\-\$|\$\-)?([1-9]{1}[0-9]{0,2}(\,[0-9]{3})*(\.[0-9]{0,2})?|[1-9]{1}[0-9]{0,}(\.[0-9]{0,2})?|0(\.[0-9]{0,2})?|(\.[0-9]{1,2})?)$
 </param>
            <message>${getText("errors.upto",{getText("category.description"),maxLength})}</message>
        </field-validator>

다른예..
<!--  ^\$?([1-9]{1}[0-9]{0,2}(\,[0-9]{3})*(\.[0-9]{0,2})?|[1-9]{1}[0-9]{0,}(\.[0-9]{0,2})?|0(\.[0-9]{0,2})?|(\.[0-9]{1,2})?)$ -->


간단한예..
12345.67 as a regex for this? 

^[0-9]{1,5}\.[0-9]{2}$ (doesn't compile in Eclipse) 
\b[0-9]{1,5}\.[0-9]{2}\b (doesn't compile in Eclipse) 
[0-9]{1,5}.[0-9]{2} (compiles, but is not correct) 

I'm using it like this btw: 
@RegexFieldValidator(key="validate.amount", fieldName="amount", 
message="", expression="[0-9]{1,5}\.[0-9]{2}") 




'Struts2' 카테고리의 다른 글

현재 URL 가져오기  (0) 2010.08.14
Struts2 @Results 에서 params이용 방법  (0) 2010.08.12
Validator 날짜 체크 Action  (0) 2010.08.11
Struts2 exceptionStack logfile  (0) 2010.08.06
Struts2 validation Byte Check  (0) 2010.08.06


Struts2에서 웹표시가 아닌 log에 에러내용을 남기고 싶을때.

Struts.xml 설정
<global-results>
<result name="error">/WEB-INF/web/jsp/error.jsp</result>
</global-results>

<global-exception-mappings>
<exception-mapping exception="java.lang.Exception" result="error"/>
</global-exception-mappings>

error.jsp 내용
<h1>ERROR</h1>
<s:actionerror/>
<p>
<s:property value="%{exception.message}"/>
</p>
<hr/>
<h3>Technical Details</h3>
<p>
<font style="font-size: 9px; color:gray">
<s:property value="%{exceptionStack}"/>
</font>
</p>
...

logfile에 남기기 위해 추가(log4j기준)
<%@page import="org.apache.log4j.Logger"%>
<s:set name="stackTrace" value="%{exceptionStack}" scope="page"/>
<%
String stackTrace = (String) pageContext.getAttribute("stackTrace");
Logger.getLogger(this.getClass()).error(stackTrace);
%>

출처:http://mr678.blogspot.com/2009/03/struts2-unchecked-exceptions-loggen.html

'Struts2' 카테고리의 다른 글

현재 URL 가져오기  (0) 2010.08.14
Struts2 @Results 에서 params이용 방법  (0) 2010.08.12
Validator 날짜 체크 Action  (0) 2010.08.11
validate money check struts2  (0) 2010.08.10
Struts2 validation Byte Check  (0) 2010.08.06

+ Recent posts