<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd"> <struts> <package name="defult" namespace="/" extends="struts-default"> <default-action-ref name="index"></default-action-ref> <action name="index"> <result>/error.jsp</result> </action> <action name="*_*" method="{2}" class="com.zsq.action.{1}Action"> <result>/result.jsp</result> <result name="add">/{2}.jsp</result> <result name="update">/{2}.jsp</result> </action> </package> </struts>
<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%> <% 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 'error.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> Sorry,not found! <br> </body> </html>
同问,我把action放在两个不同的package中问题就解决了。但是为什么放在同一个package中的时候默认的就没有用了
什么意思,{2}后加上后缀变成{2}.get吗?那样就无法运行了
12行的 method="{2}" 要改一下 method一般后面是"post"或者"get"
12行的 method="{2}" 要改一下 method一般后面是"post"或者"get"