weixin_65228302 2023-12-16 15:41 采纳率: 28.6%
浏览 5

求解,struts2

求解,struts2

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://xmlns.jcp.org/xml/ns/javaee"
    xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
    id="WebApp_ID" version="3.1">
    <welcome-file-list>
    <welcome-file>login.jsp</welcome-file>
</welcome-file-list>
    
     <filter>
    <filter-name>struts</filter-name>
    <filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
</filter>
<filter-mapping>
      <filter-name>struts</filter-name>
      <url-pattern>/*</url-pattern>
</filter-mapping>

     
 
</web-app>

struts2.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC   "EN"   "http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
   
    <package name="struts" extends="struts-default" namespace="/">
        <action name="login" class="MVC.Login" method='loginx'>
            <result name="SUCCESS">/success.jsp</result>
            <result name="ERROR">/fail.jsp</result>
        </action>
        
    </package>
</struts>

login.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8" import="MVC.Login"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>登录</title>
</head>
<body>
<form action="./login" method="post">
<input type="text" name="id" >
<input type="password" name="pwd">
<input type="submit" value="登录" >


</form>

</body>
</html>



success.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>成功</title>
</head>
<body>
<%
String id=request.getParameter("usm");
out.print("用户"+id+"登录成功");
%>

</body>
</html>


Login.java

package MVC;

import com.opensymphony.xwork2.ActionSupport;
public class Login extends ActionSupport {
    

    public String loginx(){

        if ("good".equals(id) && "123".equals(pwd)) {
            System.out.print("success");
            return "SUCCESS";
        }else {
            System.out.print("fail");
            return "ERROR";
        }
        
    }
    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getPwd() {
        return pwd;
    }

    public void setPwd(String pwd) {
        this.pwd = pwd;
    }

    private String id;
    private String pwd;
    

    

        
    }

    
    



img

img

  • 写回答

1条回答 默认 最新

  • A乐神 2023-12-16 16:02
    关注

    tomacat配置错了可以查查springmvc配置启动利用tomcat的文章。

    评论

报告相同问题?

问题事件

  • 创建了问题 12月16日