struts中form表单中的请求action路径和struts-config.xml中响应路径的注意点
2017-02-28 19:43
489 查看
举个例子:本人建立了一个ssh的项目demo,项目结构如下图所示:
这个项目有登陆界面,有login.jsp文件,这个文件的form表单请求如下
这里form表单还可以这样写
struts-config.xml中配置响应action路径如下
还有第三种路径的写法,这个写法是采用request.getContextPath()来获取项目根路径
这个项目有登陆界面,有login.jsp文件,这个文件的form表单请求如下
<body> <h1>管理员登录</h1> <form action="/ssh/login.do?flag=login" method="post"> id:<input type="text" name="id"/><br/> pw:<input type="password" name="pwd"><br/> <input type="submit" value="登陆"/> </form> </body>
这里form表单还可以这样写
<body> <h1> 4000 管理员登录</h1> <form action="login.do?flag=login" method="post"> id:<input type="text" name="id"/><br/> pw:<input type="password" name="pwd"><br/> <input type="submit" value="登陆"/> </form> </body>
struts-config.xml中配置响应action路径如下
<struts-config> <form-beans> <form-bean name="employeeForm" type="com.gt.web.forms.EmployeeForm"></form-bean> </form-beans> <action-mappings> <action path="/login" parameter="flag" name="employeeForm" type="com.gt.web.action.LoginAction"> <forward name="ok" path="/WEB-INF/mainFrame.jsp"></forward> <forward name="error" path="/WEB-INF/login.jsp"></forward> </action> </action-mappings> </struts-config>这里我们发现在表单中可以使用第一种url路径方式,这种写法是绝对路径的写法;第二种写法则是相对路径,不需要写斜杠,系统默认是该项目下,在这个项目中就是 /ssh ("ssh"为该项目名)下面。
还有第三种路径的写法,这个写法是采用request.getContextPath()来获取项目根路径
<body> <h1>管理员登录</h1> <form action="<%=request.getContextPath()%>/login.do?flag=login" method="post"> id:<input type="text" name="id"/><br/> pw:<input type="password" name="pwd"><br/> <input type="submit" value="登陆"/> </form> </body>
相关文章推荐
- struts-config.xml中action、forward、form-bean
- struts-config.xml中action、forward、form-bean属性含义
- struts-config.xml文件中的form-bean和action-bean关系
- struts-config.xml中action、forward、form-bean属性含义
- struts-config.xml中action、forward、form-bean属性含义
- struts-config.xml中action、forward、form-bean属性含义
- struts-config.xml中action、forward、form-bean属性含义
- 保持struts-config.xml不变,将动态Form org.apache.struts.action.DynaActionForm转化成ActionForm的例子
- struts-config.xml中action、forward、form-bean属性含义
- struts-config.xml中action、forward、form-bean属性含义
- struts-spring-hibernate 框架 action 请求 ,form 表单提交 id 重复问题
- struts-config.xml中action、forward、form-bean属性含义
- struts学习之form表单, 配置文件action对应关系。
- Struts的配置文件struts-config.xml中action元素的parameter属性作用
- struts请求在struts-config.xml中的配置
- [J2EE]追忆系列-Struts的配置文件struts-config.xml中action元素的parameter属性
- 在Struts中,用向导生成Form, Action&Jsp,如果删除Form需要注意事项
- struts-config.xml中action配置--> attribute和name的区别(转)
- org.apache.struts.config.FormBeanConfig.createActionForm(FormBeanConfig.java:289)
- struts2/jsp 通过form表单方式或者js的方式提交请求,封装boolean值的问题