为了账号安全,请及时绑定邮箱和手机立即绑定

无法跳转到登录界面

helloword.xml

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE struts PUBLIC

"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"

"http://struts.apache.org/dtds/struts-2.3.dtd">

<struts>

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

<default-action-ref name="index"></default-action-ref>

<action name="index">

<result>/error.jsp</result>

</action>

<action name="helloword_*" method="{1}" class="com.jia.action.HelloWordAction">

<result>/result.jsp</result>

<result name="add">/{1}.jsp</result>

<result name="update">/{1}.jsp</result>

<result name="error">/error.jsp</result>

</action>

<action name="LoginAction" method="login" class="com.jia.action.LoginAction">

<result>/success.jsp</result>

</action>

</package>

</struts>


struts.xml

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE struts PUBLIC

"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"

"http://struts.apache.org/dtds/struts-2.3.dtd">

<struts>

<include file="helloword.xml"></include>

<constant name="struts.action.extension" value=""></constant>

</struts>


web.xml

<?xml version="1.0" encoding="UTF-8"?>

<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">

  <display-name>HelloWord</display-name>

  <filter>

  <filter-name>struts2</filter-name>

  <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>

  </filter>  

  <filter-mapping>

  <filter-name>struts2</filter-name>

  <url-pattern>/*</url-pattern>

  </filter-mapping>  

  <welcome-file-list>

    <welcome-file>index.jsp</welcome-file>

  </welcome-file-list>

</web-app>


login.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"

    pageEncoding="UTF-8"%>

<!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=UTF-8">

<title>Insert title here</title>

</head>

<body>

<form action="LoginAction.action" method="post">

用户名:<input type="text" name="user.username">

密码:<input type="password" name = "user.password">

<input type = "submit" value="提交"/>

</form>

</body>

</html>


LoginAction.java

package com.jia.action;

import com.jia.po.User;

import com.opensymphony.xwork2.ActionSupport;

public class LoginAction extends ActionSupport {

private User user;

public String login(){

System.out.println(user.getUsername());

return SUCCESS;

}

public User getUser() {

return user;

}

public void setUser(User user) {

this.user = user;

}

}

success.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"

    pageEncoding="UTF-8"%>

<!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=UTF-8">

<title>Insert title here</title>

</head>

<body>

  This is success.jsp

</body>

</html>


User.java

package com.jia.po;


public class User {

private String username;

private String password;

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;

}

}


正在回答

1 回答

附上截图

http://img1.sycdn.imooc.com//5673734b0001778c07300114.jpg

0 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消
Struts2入门
  • 参与学习       95068    人
  • 解答问题       456    个

本教程带你踏上Struts2学习之旅,对Struts2进行更深入讲解

进入课程

无法跳转到登录界面

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信