struts 2 의 특별한 제출 방법
페이지 코드 는 다음 과 같 습 니 다.hidden 속성 을 가 진 input 의 name="method:test"는 이 form 을 웹/login 에 대응 하 는 action 의 test 방법 에 제출 하 겠 다 는 뜻 입 니 다.
<form action="web/login" method="post">
<input type="hidden" name="method:test" />
:<input name="name" type="text" /> <br />
:<input name="password" type="password" /> <br />
<input type="submit" value=" " />
Action 코드 는 다음 과 같 습 니 다:
package test;
import com.opensymphony.xwork2.ActionSupport;
public class Login extends ActionSupport
{
private String name;
private String password;
public String execute() throws Exception
{
if(!("".equals(name) || "".equals(password)))
return SUCCESS;
else
return INPUT;
}
public String test() throws Exception
{
return "test";
}
public String getName()
{
return name;
}
public void setName(String name)
{
this.name = name;
}
public String getPassword()
{
return password;
}
public void setPassword(String password)
{
this.password = password;
}
}
프로필 은 다음 과 같 습 니 다:
<struts>
<package name="login" namespace="/web" extends="struts-default">
<action name="login" class="test.Login">
<result name="input" type="dispatcher">/web/login.jsp</result>
<result name="success" type="dispatcher">/web/welcome.jsp</result>
<result name="test" type="dispatcher">/web/test.jsp</result>
</action>
</package>
</struts>
이런 방법의 장점 은:
1)struts 설정 파일 에 여러 개의 action 을 설정 할 필요 가 없습니다.모든 action 류 는 하나의 설정 항목 만 설정 하면 됩 니 다.
2)actionName 을 사용 합 니 다!method="test"방식 은 js 가 보조 해 야 합 니 다.이 제출 방식 은 숨겨 진 intput 하나만 있 으 면 해 결 됩 니 다.깔끔 하고 효과 적 입 니 다.
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Is Eclipse IDE dying?In 2014 the Eclipse IDE is the leading development environment for Java with a market share of approximately 65%. but ac...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.