第一个成功的struts项目

来源:互联网 发布:万象网管数据库密码 编辑:程序博客网 时间:2024/04/19 17:42

 

__________________________________第一个成功的struts项目_____________

 


//////login.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 'result.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>
   username:${requestScope.username} <br/>
   password:${requestScope.password}
  </body>
</html>
_____________________________________________________________

////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">
  <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>


_______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>
<package name="struts2" extends="struts-default">
 <action name="login" class="com.test.action.LoginAction">
  <result name="success">/result.jsp</result>
 </action>
</package>
</struts>
_________LoginAction.java_____________________

package com.test.action;

public class LoginAction {
 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;
 }
 
 public String execute() throws Exception
 {
  return "success";
 }

}
__________result.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 'result.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>
   username:${requestScope.username} <br/>
   password:${requestScope.password}
  </body>
</html>

 

 

 

 

 

 

____________________________________________________________


在Preferences/Java/Editor/Content Assist中的Auto activation triggers for Java中的将.改为.abcdefghijklmnopqrstuvwxyz

/////////////////////////////////////////JavaBean//////////////////////////////////////

////index.jsp
<%@ page language="java" contentType="text/html; charset=GB18030" pageEncoding="GB18030"%>
<!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=GB18030">
<title>Insert title here</title>
</head>
<body>
<form action="reg.jsp" method="post">
<input type="text" id="useName" name="userName"><br/>
<input type="text" id="pwd" name="pwd"><br/>
<input type="submit" value="注册">

</form>
</body>
</html>
////////////reg.jsp
<%@ page language="java" contentType="text/html; charset=GB18030" pageEncoding="GB18030"%>
<!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=GB18030">
<title>Insert title here</title>
</head>
<body>
<jsp:useBean id="reg" class="com.bean.ClassBean" scope="page">
<jsp:setProperty name="reg" property="*" />
</jsp:useBean>

用户名为:<jsp:getProperty property="userName" name="reg"/>
<br/>密码为:<jsp:getProperty property="pwd" name="reg"/>

</body>
</html>
/////////ClassBean.java
package com.bean;

public class ClassBean {
 private String userName;
 private String pwd;
 public String getUserName()
 {
  return userName;
 }
 public String getPwd()
 {
  return pwd;
 }
 public void setUserName(String userName)
 {
  this.userName=userName;
 }
 public void setPwd(String pwd)
 {
  this.pwd=pwd;
 }

}
//////////////////////////////////////////////////////////////////////////////////////////////