为什么使用使用s:form标签不能登录
admin/login.jsp文件里
- HTML code
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%><%@ taglib prefix="s" uri="/struts-tags" %><%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 'login.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> <s:form name="form1" method="post" action="admin/adminlogin.action" theme="simple"> <table cellpadding="0" cellspacing="0" align="center" width="50%"> <tr><th align="center">管理员登陆</th></tr> <tr><td>用户名:</td><td> <s:textfield name="username" label="用户名" size="20"></s:textfield></td></tr> <tr><td>密码:</td><td><s:password name="password" label="密码" value="" size="20"></s:password></td></tr> <tr><td></td><td align="left"><s:submit value="提交"></s:submit> <s:reset value="重置"></s:reset></td></tr> </table> </s:form> <br/> <hr/> <form action="admin/adminlogin.action" method="post"> <table align="center" border=1 width="300" bgcolor=#F5FFE1> <tr><td colspan="2" align="center" width="250" bgcolor="#CCCCFF">用户登录界面</td></tr> <tr><td width="50">姓名:</td><td><input type="text" name="username"/></td></tr> <tr><td width="50">密码:</td><td><input type="password" name="password" size=22/></td></tr> <tr><td align="center" colspan=2><input type="submit" value="登录"/><input type="reset" value="重置" /></td></tr> </table> </form> </body></html>
struts.xml文件里:
- XML code
<package name="admin" extends="struts-default" namespace="/admin"> <action name="adminlogin" class="loginAction" method="adminlogin"> <result name="success">/admin/index.jsp</result> <result name="error">/fail.jsp</result> <result name="input">/index.jsp</result> </action> </package>
[解决办法]
<s:form name="form1" method="post" action="/admin/adminlogin.action" theme="simple">
或
<s:form name="form1" method="post" namespace="/admin" action="adminlogin.action" theme="simple">
[解决办法]
不好意思,我也不知道,嘻嘻。
1楼的说法貌似挺对的
[解决办法]
用<s:form>就建议LZ的提交路径不要那么写了.
那样如果你的扩展名改了呢.?那不是页面要改.?
<s:form namespace="/admin" action="adminlogin"> 这个地方的action只需要填写与你struts.xml里面那个action的name一致就可以. 这样写的好处是你以后的扩展名随便换,页面上的提交路径都不用再改了.!
[解决办法]
<s:form name="form" method="post" action="/admin/adminlogin.action" theme="simple">
在Action中其默认的扩展名就是.Action; 可以去看看源码!