struts2中关于The requested resource (/Struts2/index.jsp) is not available.的问题
工程的结构如图:1:LoginAction.java:publicclassLoginAction{privateStringname;privateStringpass...
工程的结构如图:
1:LoginAction.java:
public class LoginAction {private String name;private String password;
public String getName() {
return name;}
public void setName(String name) {this.name = name;}
public String getPassword() {return password;}
public void setPassword(String password) {
this.password = password;}
public String execute(){
LoginService ls=new LoginService();
boolean flag=ls.login(name, password);
if (flag){
return "success";}else{
return "fail";}}}
2.LoginService.java
public class LoginService {
public boolean login(String name,String password){
if(name.equals("admin")&& password.equals("admin")){
return true;
}else{return false; } }}
3.struts.xml
<struts><package name="chapter" extends="struts-default">
<action name="Login" class="com.action.LoginAction">
<result name="success">/welcom.jsp</result>
<result name="fail">/index.jsp</result> </action></package></struts>
4.web.xml:
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<filter><filter-name>FilterDispatcher</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class></filter>
<filter-mapping><filter-name>FilterDispatcher</filter-name><url-pattern>/*</url-pattern></filter-mapping></web-app>
5.index.jsp
<body><%@taglib uri="/struts-tags" prefix="s" %>
<s:form action="Login">用户名:<s:textfield name="name"></s:textfield><br> 密码:<s:password name="password"></s:password> <s:submit value="登录" ></s:submit> </s:form> </body> 展开
1:LoginAction.java:
public class LoginAction {private String name;private String password;
public String getName() {
return name;}
public void setName(String name) {this.name = name;}
public String getPassword() {return password;}
public void setPassword(String password) {
this.password = password;}
public String execute(){
LoginService ls=new LoginService();
boolean flag=ls.login(name, password);
if (flag){
return "success";}else{
return "fail";}}}
2.LoginService.java
public class LoginService {
public boolean login(String name,String password){
if(name.equals("admin")&& password.equals("admin")){
return true;
}else{return false; } }}
3.struts.xml
<struts><package name="chapter" extends="struts-default">
<action name="Login" class="com.action.LoginAction">
<result name="success">/welcom.jsp</result>
<result name="fail">/index.jsp</result> </action></package></struts>
4.web.xml:
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<filter><filter-name>FilterDispatcher</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class></filter>
<filter-mapping><filter-name>FilterDispatcher</filter-name><url-pattern>/*</url-pattern></filter-mapping></web-app>
5.index.jsp
<body><%@taglib uri="/struts-tags" prefix="s" %>
<s:form action="Login">用户名:<s:textfield name="name"></s:textfield><br> 密码:<s:password name="password"></s:password> <s:submit value="登录" ></s:submit> </s:form> </body> 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询