Jsp反问页面
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'index.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body>
动态结果
一定不要忘了为动态结果的保存值设置set get方法
<ol>
<li><a href="user/user?type=1">返回success</a></li>
<li><a href="user/user?type=2">返回error</a></li>
</ol>
</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> <constant name="struts.i18n.encoding" value="UTF-8"></constant> <constant name="struts.ognl.allowStaticMethodAccess" value="true"></constant> <package name="login" extends="struts-default" namespace="/user"> <action name="user" class="com.lbx.action.UserAction"> <result>${r}</result> </action> </package> </struts>
UserAction代码
package com.lbx.action;
import com.opensymphony.xwork2.ActionSupport;
@SuppressWarnings("serial")
public class UserAction extends ActionSupport{
private int type;
private String r;
public int getType() {
return type;
}
public void setType(int type) {
this.type = type;
}
public String getR() {
return r;
}
public void setR(String r) {
this.r = r;
}
@Override
public String execute() throws Exception {
if(type==1){r="/success.jsp";}
if(type==2){r="/error.jsp";}
return SUCCESS;
}
}
success.jsp和error.jsp没写