Struts 의 페이지 제어 및 설정
1. 페이지 입력
input1. jsp 페이지
<%@ page language="java" pageEncoding="utf-8"%>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-bean" prefix="bean"%>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-html" prefix="html"%>
<html>
<head>
<title>JSP for HelloWorldForm form</title>
</head>
<body>
<html:form action="/helloWorld2">
msg : <html:text property="msg"/><html:errors property="msg"/><br/>
<html:submit/><html:cancel/>
</html:form>
</body>
</html>
threeInput. jsp 페이지
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'input3.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body>
<form action="<%=basePath%>threeInput.do" method="post">
:<input type="text" name="msg" value="" />
<input type="submit" name="method" value="insert" />
<input type="submit" name="method" value="update" />
<input type="submit" name="method" value="delete" />
</form>
</body>
</html>
2. 출력 페이지
show. jsp 페이지
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'show.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<%
String str = (String)request.getAttribute("helloWorld");
%>
<body>
1 :${helloWorld}<br>
2 :<%=str%>
</body>
</html>
3. ActionForm 클래스
public class HelloWorldForm extends ActionForm {
/*
* Generated fields
*/
/** msg property */
private String msg;
/*
* Generated Methods
*/
/**
* Method reset
* @param mapping
* @param request
*/
public void reset(ActionMapping mapping, HttpServletRequest request) {
// TODO Auto-generated method stub
}
/**
* Returns the msg.
* @return String
*/
public String getMsg() {
return msg;
}
/**
* Set the msg.
* @param msg The msg to set
*/
public void setMsg(String msg) {
this.msg = msg;
}
}
4. action 클래스
[1] HelloWorld1Action 류
public class HelloWorld1Action extends Action{
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
// TODO Auto-generated method stub
String str = "hello zhao ";
request.setAttribute("helloWorld", str);
return mapping.findForward("show");
}
}
[2] HelloWorld 2Action 류
public class HelloWorld2Action extends Action {
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
HelloWordForm helloWordForm = (HelloWordForm) form;// TODO Auto-generated method stub
String msg = helloWordForm.getMsg();
request.setAttribute("helloWorld", msg);
//response.setCharacterEncoding("utf-8");
//response.setContentType("text/html;charset=utf-8");
return mapping.findForward("show");
}
}
[3] ThreeInputAction 클래스
public class ThreeInputAction extends DispatchAction {
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
HelloWordForm helloWordForm = (HelloWordForm) form;// TODO Auto-generated method stub
return null;
}
}
2. struts - config. xml 설정
1. 입력 페이지 가 없고 action 과 출력 만 있 습 니 다.
<action-mappings >
<action path="/helloWorld1" type="com.zhao.struts.action.HelloWorld1Action">
<forward name="show" path="/WEB-INF/jsp/show.jsp" />
</action>
</struts-config>
2. 입력 페이지 가 있 고 bean 이 없 으 면 action 은 request. getParameter ("msg") 를 사용 해 야 합 니 다.매개 변수
3. 비 안 이 있다
<form-beans >
<form-bean name="helloWorldForm" type="com.zhao.struts.form.HelloWorldForm" />
</form-beans>
<action-mappings >
<action
attribute="helloWorldForm"
name="helloWorldForm"
path="/helloWorld2"
scope="request"
type="com.zhao.struts.action.HelloWorld2Action"
validate="false">
<forward name="show" path="/WEB-INF/jsp/show.jsp" />
</action>
</action-mappings >
4. 페이지 설정 입력
[1] 직접 / form / input1. jsp 탐색 은 설정 하지 않 아 도 됩 니 다.
[2]
<!--struts -->
<action forward="/WEB-INF/jsp/input1.jsp" path="/input2" />
<action include="/WEB-INF/jsp/input1.jsp" path="/input3" />
<!--struts -->
<action
path="/input4"
type="org.apache.struts.actions.ForwardAction"
parameter="/WEB-INF/jsp/input1.jsp" />
5. 다 중 단추 설정
<action
attribute="helloWorldForm"
name="helloWorldForm"
parameter="method"
path="/threeInput"
scope="request"
type="com.zhao.struts.action.ThreeInputAction">
<forward name="show" path="/WEB-INF/jsp/show.jsp" />
</action>
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 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에 따라 라이센스가 부여됩니다.