Struts2路径和中文问题

路径和中文问题;

HelloAction.java

package com.zhang;

import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;

public class HelloAction extends ActionSupport 
{
	private String name;
	
	public String add1()
	{
		System.out.println("name="+name);
		return SUCCESS;
	}
	
	public String getName()
	{
		return name;
	}
	public void setName(String name)
	{
		this.name = name;
	}
}

input.jsp

<%@ page language="java" import="java.util.*" pageEncoding="GB18030"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>



  
  
  
  
	
姓名:
struts.xml





	
    
    
	
		      
       
           /index.jsp
       
       
       
       		/index.jsp
       
    



注意:

(1) 在input.jsp的form表单中,form的action属性用相对路径出错,应该加上 <%=basePath%>user/user1!add1";

(2) 在input.jsp中输入中文时,在后台会出现乱码,应该在struts.xml中加上:  来解决乱码(对struts2.1.6之后的版本有效);



你可能感兴趣的:(Struts2)