Struts drop-down frame
[the goal]
This example is based on the previous example "The Skyst Struts Program" (see "How to implement the simplest struts program"), its goal is to implement a drop-down input box in the input page, in the output page Show the drop-down input box is selected.
The project is expanded on the basis of the previous Simple project, and it is of course a new project.
[effect]
Enter the page:
Output page:
[background knowledge]
[step]
1. Run JavaWebStudio to open the Simple project:
Select menu: "File" - "Open Project", select the simplest Struts program item Simple directory, open the project via Simple.PRJ project file.
2, open the helloword.jap file:
Open the helloword.jap file from the JavaWebStudio file manager, then switch to the toolbar, select the Struts tab, drag the "SELECT tab" to the code editing window (or Web Visual Edit window).
Right-click on the code editing window:
Select a refresh view, the web visual editing window is refreshed, as shown below:
3, join the bean variable:
In the Web Visual Edit window, the mouse light is shifted to the drop-down list box and click the right mouse button, select "Add Bean Variable", add the bean variable "SELECT" (you can also click the right mouse in HelloWordform.java) Operation):
HelloWordform.java automatically joins the SELECT variable and setSelec () and getSelect () functions (code of the black body part).
Package EmptyPRJ;
Import javax.servlet.http.httpservletRequest;
Import org.apache.struts.Action.Actionerror;
Import org.apache.struts.Action.Actionerro;
Import org.apache.struts.Action.actionform;
Import org.apache.struts.action.actionmapping;
Public Final Class HelloWordForm Extends Actionform
{
PRIVATE STRING SELECT;
Private string mybeanvariable1;
// myfiledata;
Public string getMyBeanvariable11 ()
{
Return (this.mybeanvariable1);
}
Public void setMyBeanvariable1 (String MyBeanvariable1)
{
THIS.MYBEANVARIABLE1 = MyBeanVariable1;
}
Public void setSelect (String newselect)
{
SELECT = newselect;
}
Public String getSelect ()
{
Return SELECT;
}
}
}
Replenishing the code of the black body part in the HelloWord.jsp file (other code is automatically generated):
<% @ page contenttype = "text / html; charset = GB2312" Language = "java"%>
<% @ Taglib URI = "/ Web-INF / STRUTS-Bean.TLD" prefix = "bean"%> <% @ Taglib URI = "/ Web-INF / STRUTS-HTML.TLD" prefix = "html"%>
<% @ Taglib URI = "/ Web-INF / STRUTS-LOGIC.TLD" prefix = "logic"%>
<% @ Taglib URI = "/ Web-INF / STRUTS-TEMPLATE.TLD" prefix = "template"%>
title>
<
Meta
http-equiv = content-type content = "text / html; charSet = GB2312">
hEAD>
Action = "/ hellowordaction.do"> html: select> html: form> body> html: html> Add the SELECT Variable Output Tags in the HelloWordout.jsp file <% @ page contenttype = "text / html; charset = GB2312" Language = "java"%> <% @ Taglib Uri = "/ Web-INF / STRUTS-Bean.tld" prefix = "bean"%> <% @ Taglib URI = "/ Web-INF / STRUTS-HTML.TLD" prefix = "html"%> <% @ Taglib URI = "/ Web-INF / STRUTS-LOGIC.TLD" prefix = "Logic"%> <% @ Taglib URI = "/ Web-INF / STRUTS-TEMPLATE.TLD" prefix = "Template"%>
hEAD>
hEAD>
p>
body>
html: html>
body>
html: html>
Look at the contents of the configuration file struts-config.xml, in the JavaWebStudio integrated development environment, struts-config.xml is generally configured, so don't write code yourself:
Xml Version = "1.0" encoding = "ISO-8859-1"?>
"- // Apache Software Foundation // DTD Struts Configuration 1.0 // En"
"http://jakarta.apache.org/struts/dtds/struts-config_1_0.dtd">
TYPE = "EMPTYPRJ.HELLOWORM" /> form-beans> TYPE = "EMPTYPRJ.HELLOWORDACTION" Name = "HelloWordform" Scope = "session" Input = "/ helloword.jsp"> action-mappings> Struts-Config> 4, compile, start the server: 5, start the server: Click the Start Server button on the toolbar or select the menu "Run" - Start the server launch the server Jakarta-Tomcat server. The content is as follows: Click on the Compile button on the toolbar or select the menu "Generate" - "Compile" Start Project Compile. The compilation process and the result is displayed in the output column. The output results indicate that the projects set by using ANT Compilation Build.xml have been successful. Copy the compilation result into the Tomcat server webapps directory and generate the package file Simple.war. 6, run: Open the HelloWord.jap file, click the Run button or selection menu on the toolbar or select the "-" Run (web browse) "At this time, open the results of the HelloWord.jsp. Enter "Select" in the input box in the Run Results page, and select "Second Item" in the drop-down box, then click the "Submit" button, then forward to the hellowordout.jsp file, the HelloWordout.jsp page output "Select" The word, the second line outputs "second item" in the selection result. *********************************************************** ***************************** [Extension part] The above is to implement the data fill of the drop-down list box by manually writing Modify the HelloWordAction.java file: First join: Import java.util.list; Import java.util.arraylist; Then join: List mylist = new arraylist (); MyList.Add ("first"); MyList.Add ("second item"); MyList.Add ("third item"); Request.setattribute ("MyList", MyList); Modify the helloword.jsp file: Put the original content: html: select> Rewriting: html: select> Finally compile, start the server, run the helloword.jsp file, but the following error appears: