67,515
社区成员
发帖
与我相关
我的任务
分享
<%@ page language="java" contentType="text/html; charset=UTF-8"
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"%>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-logic" prefix="logic"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>STRUTS3</title>
<script type="text/javascript">
function jump(){
document.forms[0].action = "/HelloWorld.do?verb=3";
alert(document.forms[0].action);
document.forms[0].submit();
}
</script>
</head>
<body>
<form>
<html:link page="/HelloWorld.do?verb=1">HelloWorld_1</html:link>
<html:link page="/HelloWorld.do?verb=2">HelloWorld_2</html:link>
<input type=button value="3333" onclick="jump();"/>
</form>
</body>
</html>
struts-config文件:
<?xml version="1.0"?>
<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.1//EN" "http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd">
<struts-config>
<data-sources>
</data-sources>
<form-beans>
</form-beans>
<global-exceptions>
</global-exceptions>
<global-forwards>
</global-forwards>
<action-mappings>
<action parameter="verb" path="/HelloWorld" type="hello.HelloAction" scope="request" validate="true" input="/hello.jsp">
<forward name="Hello_1" path="/HelloWorld_1.jsp"/>
<forward name="Hello_2" path="/HelloWorld_2.jsp"/>
<forward name="Hello_3" path="/HelloWorld_3.jsp"/>
</action>
</action-mappings>
<controller/>
</struts-config>
package hello;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
public class HelloAction extends Action {
public ActionForward execute(ActionMapping map, ActionForm form,
HttpServletRequest request, HttpServletResponse response) throws Exception {
String para = (String)request.getParameter("verb");
if(para.equals("1")){
return (map.findForward("Hello_1"));
}
if(para.equals("2")){
return (map.findForward("Hello_2"));
}
if(para.equals("3")){
return (map.findForward("Hello_3"));
}
else{
return null;
}
}
}