You are on page 1of 11

eclipse jsp

1JDK 1.5

https://jsecom15b.sun.com/ECom/EComActionServlet
/DownloadPage:~:com.sun.
sunit.sdlc.content.DownloadPageInfo;
jsessionid=502E87C71D77E3BC297C08B35
DAC9AD4;jsessionid=502E87C71D77E3BC297C08B35DAC9AD4
jdk-1_5_0_05-windows-i586-p.exe
2tomcat 5.5.9
http://jakarta.apache.org/site/downloads/downloads_tomcat-5.cgi
5.5.11alpha
5.5.9 exe
3Sysdeo Eclipse Tomcat Launcher plugin 3.1beta
http://www.sysdeo.com/eclipse/tomcatplugin
tomcatPluginV31beta.zip
4eclipse 3.1
http://www.eclipse.org/downloads/index.php
JDT Eclipse SDK
JDT eclipse

eclipse-SDK-3.1-win32.zip
5GEF 3.1

http://download.eclipse.org/tools/gef/downloads/drops/R-3.1-200507071758/
index.php

GEF-ALL-3.1.zip
6Eclipse HTML Editor 1.6.7
https://sourceforge.jp/projects/amateras/files/?release_id=16537
#16537
tk.eclipse.plugin.htmleditor_1.6.7.zip
7StrutsIDE 1.1.7
https://sourceforge.jp/projects/amateras/files/?release_id=16537#16537
tk.eclipse.plugin.struts_1.1.7.zip

JDK
JDK exe JDK
bin path JRE lib rt.jar
classpath
JDK C:\Program Files\Java\jdk1.5.0_02
JDK
tomcat
tomcat exe
D:\Tomcat5.5 12345678
Eclipse
eclipse-SDK-3.1-win32.zip eclipse
eclipse D:\eclipse
eclipse.exe eclipse
E:\workspace Use this
as the default and do not ask again
eclipse

tomcatPlugin
tomcatPluginV31beta.zip
com.sysdeo.eclipse.tomcat_3.1.0.beta D:\eclipse\plugins
eclipseOK,
tomcat eclipse window/preferences
tomcat
tomcat version 5.x tomcat home D:\Tomcat5.5
Contexts directory D:\Tomcat5.5\conf\Catalina\localhost tomcat plugin
GEF
GEF-ALL-3.1.zip eclipse D:\eclipse

GEF

eclipse

1 Sysdeo Tomcat Plugin tomcat


File ->new->others java->tomcat projects next
projects name textweb Use default next
finished eclipse package explorer
testweb
2 struts
File->new->others Amateras->Struts->Add Struts Support
next
Finish eclipse package explorer
struts WEB-INF struts
Struts
3 struts-config.xml
WEB -INF open with->Amateras XML Editer
xml open with->struts-config.xml editor

outline struts
struts-config.xml
4 index.jsp
File->new->others Amateras->JSP File next FileName
index.jsp Finish index.jsp
<%@page pageEncoding="GBK"
contentType="text/html;
charset=gb2312" %>
<html>
<head>
<meta http-equiv="Content-Type"
content="text/html;
charset=gb2312"/>
<title></title>
</head>
<body>
<form name="form1" method="post"
action="/testweb/logincheck.do">
<table width="300" border="0"
cellspacing="0" cellpadding="0">
<tr align="center">
<td colspan="2"></td>
</tr>
<tr>
<td></td>
<td>
<input name="username"
type="text" id="username"
size="12">
user
</td>
</tr>
<tr>
<td></td>
<td>
<input name="password"
type="text" id="password"
size="12">
123456
</td>

</tr>
<tr align="center">
<td colspan="2"><input
type="submit" name="Submit"
value=""></td>
</tr>
</table>
</form>
</body>
</html>
5 form
File->new->package
name com.is.form Finish
Package
Explorer com.is.form new->others
Amateras->struts->Struts Action Form next name LoginForm
Finish
LoginForm
package com.is.form;
import org.apache.struts.action.ActionForm;
public class LoginForm extends ActionForm
{
private static final long
serialVersionUID = 1L;
private String username = "";
private String password = "";
/**
* @return Returns the password.
*/
public String getPassword()
{
return password;
}
/**
* @param password The password to set.
*/
public void setPassword(String password)
{
this.password = password;
}

/**
* @return Returns the username.
*/
public String getUsername()
{
return username;
}
/**
* @param username The username to set.
*/
public void setUsername(String username)
{
this.username = username;
}
}
jsp form
struts form get set
eclipse source
eclipse
Eclipse HTML Editor
tk.eclipse.plugin.htmleditor_1.6.7.zip plugins D:\eclipse
Eclipse HTML Editor
StrutsIDE
tk.eclipse.plugin.struts_1.1.7.zip plugins D:\eclipse

StrutsIDE
6 action
form com.is.action
Struts Action LoginAction.java LoginAction

package com.is.action;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;

import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import com.is.form.LoginForm;
public class LoginAction extends Action
{
private static final long serialVersionUID = 1L;
public ActionForward execute
(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws Exception {
// this line is here for when the
input page is upload-utf8.jsp,
// it sets the correct character
encoding for the response
String encoding = request.getCharacterEncoding();
if ((encoding != null) &&
(encoding.equalsIgnoreCase("GB2312")))
{
response.setContentType
("text/html; charset=GB2312");
} else {
response.setContentType
("text/html; charset=GBK");
}
try {
if (form instanceof LoginForm)
{
LoginForm theForm = (LoginForm) form;

if(theForm.getUsername().equals("user") &&
theForm.getPassword().equals("123456"))
{
return new ActionForward("/welcome.do?type=true");
}

else {
return new ActionForward("/welcome.do?type=false");
}
}
} catch (Exception e)
{
}
// this shouldn't happen in this example
return null;
}
}
ActionForward struts
struts-blank.war
7
index.jsp welcome.jsp

<%@page pageEncoding="GBK"
contentType="text/html;
charset=GBK" %>
<html>
<head>
<meta http-equiv="Content-Type"

content="text/html;
charset=GBK"/>
<title></title>
</head>
<body>
<%
String type = request.getParameter("type");
if(type!=null&&type.equals("true")){
out.print("");
}
else{
out.print("");
}
%>
</body>
</html>
8 Struts-config.xml
formbean
<form-bean
name="loginForm"
type="com.is.form.LoginForm"/>
jsp
<action
path="/index"
forward="/index.jsp"/>
<action
path="/welcome"
forward="/welcome.jsp"/>
action
path="/logincheck"
type="com.is.action.LoginAction"
name="loginForm"
scope="request"
validate="true"/>

struts-config.xml
<?xml version="1.0"?>
<!DOCTYPE struts-config PUBLIC "//Apache Software Foundation
//DTD Struts Configuration 1.2//EN"
"http://struts.apache.org/dtds
/struts-config_1_2.dtd">
<struts-config>
<data-sources>
</data-sources>
<form-beans>
<form-bean
name="loginForm"
type="com.is.form.LoginForm"/>
</form-beans>
<global-exceptions>
</global-exceptions>
<global-forwards>
</global-forwards>
<action-mappings>
<action
path="/index"
forward="/index.jsp"/>
<action
path="/welcome"
forward="/welcome.jsp"/>
<action
path="/logincheck"
type="com.is.action.LoginAction"
name="loginForm"
scope="request"
validate="true"/>
</action-mappings>
<controller processorClass=
"org.apache.struts.tiles.TilesRequestProcessor"/>
<message-resources parameter="MessageResources"/>
<plug-in className=
"org.apache.struts.tiles.TilesPlugin">
<set-property property="definitions-config"
value="/WEB-INF/tiles-defs.xml"/>
<set-property property="moduleAware" value="true"/>
</plug-in>
<plug-in className=

"org.apache.struts.validator.ValidatorPlugIn">
<set-property property="pathnames"
value="/WEB-INF/validator-rules.xml,
/WEB-INF/validation.xml"/>
</plug-in>
</struts-config>

9
testweb Tomcate project->update context definition
tomcat
tomcat IE
http://localhost:8080/testweb/index.jsp index.jsp


CSDN

http://blog.csdn.net/network97/archive/2008/01/23/2061597.aspx

You might also like