gpt4 book ai didi

java - 使用 JAVA 的 struts2 中的简单登录 Web 应用程序的第二页未加载?

转载 作者:太空宇宙 更新时间:2023-11-04 07:16:17 26 4
gpt4 key购买 nike

我创建了以下代码。但是在 apache tomcatv6.0 服务器中运行时,第二页即 Welcome.jsp 未加载,而第一页即 Login.jsp 已成功加载。有人能说编码有什么问题吗?我已经在 J​​ava Resources 文件夹内的 src 文件夹内创建了 struts.xml。我正在使用 eclipse IDE。

StrutsDemo.java

package com.vishnu.struts;

import com.opensymphony.xwork2.ActionSupport;

public class StrutsDemo extends ActionSupport{
String username;
String password;
String returnString=null;

public String execute()
{
if(getUsername().equals("abc")&&getPassword().equals("abc123"))
{

returnString=SUCCESS;

}
else {
returnString=ERROR;
}
return returnString;


}

public String getUsername() {
return username;
}

public void setUsername(String username) {
this.username = username;
}

public String getPassword() {
return password;
}

public void setPassword(String password) {
this.password = password;
}

}

登录.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="s" uri="/struts-tags"%>


<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Still TRY TRY...</title>
</head>
<body>

<s:textfield name="username"/>
<s:password name="password" value="Password"/>
<s:submit method="execute" label="Click" action="doLogin"/>


</body>
</html>

欢迎.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Thank God...</title>
</head>
<body>
<h1>Gud to see you!!!</h1>

</body>
</html>

struts.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" "http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>

<package name="default" namespace="/" extends="struts-default">


<action name="doLogin" class="com.vishnu.struts.StrutsDemo" method="execute">

<result name="success">/Welcome.jsp</result>
<result name="error">/Login.jsp</result>
</action>
</package>
</struts>

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>STRUTS INTRO-VISHNU</display-name>

<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
</filter>

<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>


<welcome-file-list>
<welcome-file>Login.jsp</welcome-file>

最佳答案

试试这个。你没有表格,那么你的字段是如何发布的..

   <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="s" uri="/struts-tags"%>


<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Still TRY TRY...</title>
</head>
<body>
<s:form action="doLogin">
<s:textfield name="username"/>
<s:password name="password" value="Password"/>
<s:submit label="Click"/>
</s:form>

</body>
</html>

关于java - 使用 JAVA 的 struts2 中的简单登录 Web 应用程序的第二页未加载?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19927267/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com