Learn to use the Action property to accept parameters

Source: Internet
Author: User

1. Configure the Java JDK version. property to configure the version in Java Compier.

2, to create useraction.

public class Useraction extends Actionsupport {

private String name;
private int age;

Public String Add () {
System.out.println ("name=" + name);
System.out.println ("age=" + age);
return SUCCESS;
}

Public String GetName () {
return name;
}

public void SetName (String name) {
THIS.name = name;
}

public int getage () {
return age;
}

public void Setage (int.) {
This.age = age;
}
3, the same as the last study to configure struts,

<?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.devmode" value= "true"/>
<package name= "user" extends= "struts-default" namespace= "/user" >

<action name= "user" class= "com.bjsxt.struts2.user.action.UserAction" >
<result>/user_add_success.jsp</result>
</action>
</package>
</struts>

4, Webroot

<?xml version= "1.0" encoding= "GB18030"?>
<%@ page language= "java" contenttype= "text/html; charset=gb18030 "
pageencoding= "GB18030"%>

<%
String path = Request.getcontextpath ();
String basepath = request.getscheme () + "://" +request.getservername () + ":" +request.getserverport () +path+ "/";
%>

<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<meta http-equiv= "Content-type" content= "text/html; charset=gb18030 "/>
<base href= "<%=basepath%>"/>
<title>insert title here</title>
<body>
Use the Action property to receive parameters <a href= "User/user!add?name=a&age=8" > Add Users </a>

</body>

Here we use how to use the Action property to accept parameters.

5. The user added success is shown here.

<?xml version= "1.0" encoding= "GB18030"?>
<%@ page language= "java" contenttype= "text/html; charset=gb18030 "
pageencoding= "GB18030"%>
<% @taglib uri= "/struts-tags" prefix= "s"%>
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<meta http-equiv= "Content-type" content= "text/html; charset=gb18030 "/>
<title>insert title here</title>
<body>
Add User Success! haha haha haha haha ha ha ha ha haha haha hahaha!!!!!!!!!!!!!!!!!!!
</body>

Learn to use the Action property to accept parameters

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.