jar包都放进去会产生冲突,放必要的就够了
解决方案 »
- 如何eWebEditor 硬回车问题
- Cannot create resource instance怎么解决?
- 求JSP版支付宝源码
- jsf怎么在tomcat下运行?
- 谁能告诉我
- JSP 连接SQLSERVER2005 遇到的怪异问题
- 自动跳转页面问题!!急求解决!!
- 点击某个操作,怎么无故出现下载的对话框?急呀,在线等待。
- 请问那里有SYBASE的jbdb 2.0下载;jspsmartupload可以直接将文件上传到数据库,请问如何使用
- 请问我在JSP中的同一个form表单里即有其他文本字段,又有上传的文件的输入框,怎么做?
- java.lang.NoSuchMethodError: antlr.collections.AST.getLine()I,求教,错误
- 高难度问题:java mysql海量数据复制 一致性问题
正确写法是:
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">而你写的是:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"system11"
"struts-2.0.dtd">这个最好直接到官网上下载,直接复制粘贴
在这里的.xml格式就是这个图标的,
/**
*
*/
package com.you.action;import com.opensymphony.xwork2.ActionSupport;/**
* @author Administrator
*
*/
public class StudentAction extends ActionSupport
{
/**
*
*/
private static final long serialVersionUID = 1L;
private String message; @Override
public String execute() throws Exception
{
if("".equals(message))
{
return "error";
}
else
{
return "success";
}
} /**
* @return the message
*/
public String getMessage() {
return message;
} /**
* @param message the message to set
*/
public void setMessage(String message) {
this.message = message;
}}
struts.xml:
<!--
/*
* $Id: struts.xml 1364077 2012-07-21 12:57:02Z lukaszlenart $
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
-->
<!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" extends="struts-default">
<action name="StudentAction" class="com.you.action.StudentAction">
<result name="success">student.jsp</result>
<result name="error">error.jsp</result>
</action>
</package>
</struts>web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<display-name></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>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
student.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 'student.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>
<form id="form1" name="form1" method="post" action="StudentAction.action">
<p>输入信息:
<input type="text" name="message" id="username"/>
</p>
<p><input type="submit" name="submit" value="提交"></p>
</form>
</body>
</html>error.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 'error.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>
This is my JSP page. <br>
</body>
</html>
浏览器地址:http://localhost:8080/struts/student.jsp
当输入框中输入“you”点击“提交”,会将内容提交;当输入框中的内容为空时,点击提交
地址栏的地址变为:http://localhost:8080/struts/StudentAction.action
public class HelloWorld extends ActionSupport {
...............
}
StudentAction.java
package com.you.action;import com.opensymphony.xwork2.ActionSupport;public class StudentAction extends ActionSupport{
private static final long serialVersionUID=1L;
private String message;
public String execute() throws Exception
{
if("".equals(message))
{
return "error";
}
else
{
return "success";
}
}
public String getMessage(){
return message;
}
public void setMessage(String message){
this.message=message;
}
}
struts.xml
<!--
/*
* $Id: struts.xml 1364077 2012-07-21 12:57:02Z lukaszlenart $
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
-->
<!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" extends="struts-default">
<action name="StudentAction" class="com.you.action.StudentAction">
<result name="success">student.jsp</result>
<result name="error">error.jsp</result>
</action>
</package>
</struts>
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<display-name></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>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
student.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 'student.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>
<form id="form1" name="form1" method="post" action="StudentAction.action">
<p>输入信息:
<input type="text" name="message" id="username"/>
</p>
<p><input type="submit" name="submit" value="提交"></p>
</form>
</body>
</html>
error.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 'error.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>
This is my JSP page. <br>
</body>
</html>
这里改成这样试试 <result name="success">/student.jsp</result>
<result name="error">/error.jsp</result>
这里改成这样试试 <result name="success">/student.jsp</result>
<result name="error">/error.jsp</result>
也不行额
[email protected] 发邮箱吧