我创建了一个使用Struts 2框架的动态Web项目。我的问题是我无法在我的jsp文件中显示字符串。我已经有我的吸气剂和吸气剂。
在控制台中显示消息“ Hello from execute”,但是未显示我在属性中设置的文本。试图通过使用相等的运算符和设置器来设置值,以确保Im设置值。试图在线搜索如何获得财产价值,但没有一个能解决我的问题。
这是我的动作课:
package com.tutorial.action;
import com.opensymphony.xwork2.ActionSupport;
public class TutorialAction extends ActionSupport{
private String userName;
private String password;
public String execute() {
System.out.print("Hello from execute");
userName = "Test";
setPassword("Test");
return "success";
}
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;
}
}
error.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>Insert title here</title>
</head>
<body>
<h2>
<s:property value="userName"/>
<s:property value="password"/>
</h2>
</body>
</html>
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>
<constant name="struts.devMode" value="true"/>
<package name="default" namespace="/hello" extends="struts-default">
<action name="getTutorial" method="execute" class="com.tutorial.action.TutorialAction">
<result name="success">/error.jsp</result>
</action>
</package>
</struts>